Skip to content

Commit 0d2b479

Browse files
committed
docs: add client section on custom implementation
1 parent 2bae35a commit 0d2b479

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

docs/openapi-ts/clients/axios.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ When we installed the client above, it created a [`client.gen.ts`](/openapi-ts/o
6464

6565
### `setConfig()`
6666

67-
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Axios configuration option to `setConfig()` (except for `auth`), and even your own Axios implementation.
67+
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Axios configuration option to `setConfig()` (except for `auth`), and even your own [Axios](#custom-axios) implementation.
6868

6969
```js
7070
import { client } from 'client/client.gen';
@@ -206,5 +206,21 @@ const url = client.buildUrl<FooData>({
206206
console.log(url); // prints '/foo/1?bar=baz'
207207
```
208208

209+
## Custom `axios`
210+
211+
You can implement your own `axios` instance. This is useful if you need to extend the default `axios` instance with extra functionality, or replace it altogether.
212+
213+
```js
214+
import { client } from 'client/client.gen';
215+
216+
client.setConfig({
217+
axios: () => {
218+
/* custom `axios` instance */
219+
},
220+
});
221+
```
222+
223+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
224+
209225
<!--@include: ../../examples.md-->
210226
<!--@include: ../../sponsors.md-->

docs/openapi-ts/clients/fetch.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ When we installed the client above, it created a [`client.gen.ts`](/openapi-ts/o
7070

7171
### `setConfig()`
7272

73-
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation.
73+
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own [Fetch](#custom-fetch) implementation.
7474

7575
```js
7676
import { client } from 'client/client.gen';
@@ -283,5 +283,21 @@ const url = client.buildUrl<FooData>({
283283
console.log(url); // prints '/foo/1?bar=baz'
284284
```
285285

286+
## Custom `fetch`
287+
288+
You can implement your own `fetch` method. This is useful if you need to extend the default `fetch` method with extra functionality, or replace it altogether.
289+
290+
```js
291+
import { client } from 'client/client.gen';
292+
293+
client.setConfig({
294+
fetch: () => {
295+
/* custom `fetch` method */
296+
},
297+
});
298+
```
299+
300+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
301+
286302
<!--@include: ../../examples.md-->
287303
<!--@include: ../../sponsors.md-->

docs/openapi-ts/clients/next-js.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ With this approach, `client.gen.ts` will call `createClientConfig()` before init
9292

9393
### `setConfig()`
9494

95-
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation.
95+
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own [Fetch](#custom-fetch) implementation.
9696

9797
```js
9898
import { client } from 'client/client.gen';
@@ -270,5 +270,21 @@ const url = client.buildUrl<FooData>({
270270
console.log(url); // prints '/foo/1?bar=baz'
271271
```
272272

273+
## Custom `fetch`
274+
275+
You can implement your own `fetch` method. This is useful if you need to extend the default `fetch` method with extra functionality, or replace it altogether.
276+
277+
```js
278+
import { client } from 'client/client.gen';
279+
280+
client.setConfig({
281+
fetch: () => {
282+
/* custom `fetch` method */
283+
},
284+
});
285+
```
286+
287+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
288+
273289
<!--@include: ../../examples.md-->
274290
<!--@include: ../../sponsors.md-->

docs/openapi-ts/clients/nuxt.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ When we installed the client above, it created a [`client.gen.ts`](/openapi-ts/o
8686

8787
### `setConfig()`
8888

89-
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Nuxt configuration option to `setConfig()`, and even your own `$fetch` implementation.
89+
This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Nuxt configuration option to `setConfig()`, and even your own [`$fetch`](#custom-fetch) implementation.
9090

9191
```js
9292
import { client } from 'client/client.gen';
@@ -232,5 +232,21 @@ const url = client.buildUrl<FooData>({
232232
console.log(url); // prints '/foo/1?bar=baz'
233233
```
234234

235+
## Custom `$fetch`
236+
237+
You can implement your own `$fetch` method. This is useful if you need to extend the default `$fetch` method with extra functionality, or replace it altogether.
238+
239+
```js
240+
import { client } from 'client/client.gen';
241+
242+
client.setConfig({
243+
$fetch: () => {
244+
/* custom `$fetch` method */
245+
},
246+
});
247+
```
248+
249+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
250+
235251
<!--@include: ../../examples.md-->
236252
<!--@include: ../../sponsors.md-->

0 commit comments

Comments
 (0)