MCPcopy
hub / github.com/ecyrbe/zodios / request

Method request

src/zodios.ts:259–287  ·  view source on GitHub ↗

* make a request to the api * @param config - the config to setup zodios options and parameters * @returns response validated with zod schema provided in the api description

(
    config: Path extends ZodiosPathsByMethod<Api, M>
      ? ReadonlyDeep<ZodiosRequestOptions<Api, M, Path>>
      : ReadonlyDeep<ZodiosRequestOptions<Api, M, ZodiosPathsByMethod<Api, M>>>
  )

Source from the content-addressed store, hash-verified

257 * @returns response validated with zod schema provided in the api description
258 */
259 async request<M extends Method, Path extends string>(
260 config: Path extends ZodiosPathsByMethod<Api, M>
261 ? ReadonlyDeep<ZodiosRequestOptions<Api, M, Path>>
262 : ReadonlyDeep<ZodiosRequestOptions<Api, M, ZodiosPathsByMethod<Api, M>>>
263 ): Promise<
264 ZodiosResponseByPath<
265 Api,
266 M,
267 Path extends ZodiosPathsByMethod<Api, M> ? Path : never
268 >
269 > {
270 let conf = config as unknown as ReadonlyDeep<AnyZodiosRequestOptions>;
271 const anyPlugin = this.getAnyEndpointPlugins()!;
272 const endpointPlugin = this.findEnpointPlugins(conf.method, conf.url);
273 conf = await anyPlugin.interceptRequest(this.api, conf);
274 if (endpointPlugin) {
275 conf = await endpointPlugin.interceptRequest(this.api, conf);
276 }
277 let response = this.axiosInstance.request({
278 ...omit(conf as AnyZodiosRequestOptions, ["params", "queries"]),
279 url: replacePathParams(conf),
280 params: conf.queries,
281 });
282 if (endpointPlugin) {
283 response = endpointPlugin.interceptResponse(this.api, conf, response);
284 }
285 response = anyPlugin.interceptResponse(this.api, conf, response);
286 return (await response).data;
287 }
288
289 /**
290 * make a get request to the api

Callers 8

injectAliasEndpointsMethod · 0.95
getMethod · 0.95
postMethod · 0.95
putMethod · 0.95
patchMethod · 0.95
deleteMethod · 0.95
zodios.test.tsFile · 0.80
interceptRequestMethod · 0.80

Calls 6

getAnyEndpointPluginsMethod · 0.95
findEnpointPluginsMethod · 0.95
omitFunction · 0.90
replacePathParamsFunction · 0.90
interceptRequestMethod · 0.80
interceptResponseMethod · 0.80

Tested by

no test coverage detected