From 8a8df6ef7ac65d3e732f20a5b9d01f2aaf3a741e Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Mon, 29 Jan 2024 09:04:19 -0800 Subject: [PATCH] Docs fixes --- docs/openapi-fetch/api.md | 4 +-- docs/openapi-fetch/middleware-auth.md | 41 ++------------------------- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/docs/openapi-fetch/api.md b/docs/openapi-fetch/api.md index 7cfbf602a..e6dfc38ee 100644 --- a/docs/openapi-fetch/api.md +++ b/docs/openapi-fetch/api.md @@ -124,7 +124,7 @@ onRequest(req, options) { | Name | Type | Description | | :-------- | :-----------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `req` | `MiddlewareRequest` | A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) with `schemaPath` (OpenAPI pathname) and `params` ([params](/openapi-fetch/api#fetch-options) object) | -| `options` | `MergedOptiosn` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | +| `options` | `MergedOptions` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | And it expects either: @@ -143,7 +143,7 @@ onResponse(res, options) { | Name | Type | Description | | :-------- | :-----------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `req` | `MiddlewareRequest` | A standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). | -| `options` | `MergedOptiosn` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | +| `options` | `MergedOptions` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | And it expects either: diff --git a/docs/openapi-fetch/middleware-auth.md b/docs/openapi-fetch/middleware-auth.md index 3e1ceacc2..3062b297f 100644 --- a/docs/openapi-fetch/middleware-auth.md +++ b/docs/openapi-fetch/middleware-auth.md @@ -33,51 +33,14 @@ const client = createClient({ baseUrl: "https://myapi.dev/v1/" }); client.use(myMiddleware); ``` +To learn more about `onRequest()` and `onResponse()` [see the API](/api#middleware) + ::: tip The order in which middleware are registered matters. For requests, `onRequest()` will be called in the order registered. For responses, `onResponse()` will be called in **reverse** order. That way the first middleware gets the first “dibs” on requests, and the final control over responses. ::: -### onRequest - -```ts -onRequest(req, options) { - // … -} -``` - -`onRequest()` takes 2 params: - -| Name | Type | Description | -| :-------- | :-----------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `req` | `MiddlewareRequest` | A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) with `schemaPath` (OpenAPI pathname) and `params` ([params](/openapi-fetch/api#fetch-options) object) | -| `options` | `MergedOptiosn` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | - -And it expects either: - -- **If modifying the request:** A [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) -- **If not modifying:** `undefined` (void) - -### onResponse - -```ts -onResponse(res, options) { - // … -} -``` - -`onResponse()` also takes 2 params: -| Name | Type | Description | -| :-------- | :-----------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `req` | `MiddlewareRequest` | A standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). | -| `options` | `MergedOptiosn` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) | - -And it expects either: - -- **If modifying the response:** A [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) -- **If not modifying:** `undefined` (void) - ### Skipping If you want to skip the middleware under certain conditions, just `return` as early as possible: