* 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>>>
)
| 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 |
no test coverage detected