You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`bodySerializer`| BodySerializer | (optional) Provide a [bodySerializer](#bodyserializer)|
38
38
|`parseAs`|`"json"`\|`"text"`\|`"arrayBuffer"`\|`"blob"`\|`"stream"`| (optional) Parse the response using [a built-in instance method](https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods) (default: `"json"`). `"stream"` skips parsing altogether and returns the raw stream. |
39
39
|`fetch`|`fetch`| Fetch instance used for requests (default: fetch from `createClient`) |
By default, this library serializes query parameters using `style: form` and `explode: true`[according to the OpenAPI specification](https://swagger.io/docs/specification/serialization/#query). To change the default behavior, you can supply your own `querySerializer()` function either on the root `createClient()` as well as optionally on an individual request. This is useful if your backend expects modifications like the addition of `[]` for array params:
Similar to [querySerializer](#querySerializer), bodySerializer allows you to customize how the requestBody is serialized if you don’t want the default [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) behavior. You probably only need this when using `multipart/form-data`:
Middleware can be a simple object. But wrapping in a function like the examples show lets you optionally create multiple instances of the same logic to handle different scenarios if needed.
-**If modifying the response:** A [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
156
151
-**If not modifying:**`undefined` (void)
152
+
153
+
### Skipping
154
+
155
+
If you want to skip the middleware under certain conditions, just `return` as early as possible:
156
+
157
+
```ts
158
+
onRequest(req) {
159
+
if (req.schemaPath!=="/projects/{project_id}") {
160
+
returnundefined;
161
+
}
162
+
// …
163
+
}
164
+
```
165
+
166
+
This will leave the request/response unmodified, and pass things off to the next middleware handler (if any). There’s no internal callback or observer library needed.
167
+
168
+
### Ejecting middleware
169
+
170
+
To remove middleware, call `client.eject(middleware)`:
Copy file name to clipboardExpand all lines: docs/openapi-fetch/examples.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Example code of using openapi-fetch with other frameworks and libraries.
8
8
9
9
## React + React Query
10
10
11
-
[React Query](https://tanstack.com/query/latest) is a perfect wrapper for openapi-fetch in React. At only 13 kB, it provides clientside caching and request deduping across async React components without too much client weight in return. And its type inference preserves openapi-fetch types perfectly with minimal setup.
11
+
[React Query](https://tanstack.com/query/latest) is a perfect wrapper for openapi-fetch in React. At only 13 kB, it provides clientside caching without too much client weight in return. And its stellar type inference preserves openapi-fetch types perfectly with minimal setup.
12
12
13
13
[View a code example in GitHub](https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-fetch/examples/react-query)
0 commit comments