Skip to content

Commit efd4e88

Browse files
authored
Merge pull request #2642 from brolnickij/feat/ofetch
feat: init `client-ofetch`
2 parents b59afd5 + 0e4a063 commit efd4e88

File tree

206 files changed

+49756
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+49756
-184
lines changed

.changeset/init-ofetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
feat: add `ofetch` client available as `@hey-api/client-ofetch`

docs/.vitepress/config/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export default defineConfig({
103103
link: '/openapi-ts/clients/nuxt',
104104
text: 'Nuxt',
105105
},
106+
{
107+
link: '/openapi-ts/clients/ofetch',
108+
text: 'OFetch',
109+
},
106110
{
107111
link: '/openapi-ts/clients/effect',
108112
text: 'Effect <span data-soon>soon</span>',

docs/openapi-ts/clients.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Hey API natively supports the following clients.
3030
- [Axios](/openapi-ts/clients/axios)
3131
- [Next.js](/openapi-ts/clients/next-js)
3232
- [Nuxt](/openapi-ts/clients/nuxt)
33+
- [OFetch](/openapi-ts/clients/ofetch)
3334
- [Effect](/openapi-ts/clients/effect) <span data-soon>Soon</span>
3435
- [Legacy](/openapi-ts/clients/legacy)
3536

docs/openapi-ts/clients/angular.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ const url = client.buildUrl<FooData>({
231231
console.log(url); // prints '/foo/1?bar=baz'
232232
```
233233

234-
## Custom `httpClient`
234+
## Custom Instance
235235

236-
You can implement your own `httpClient`. This is useful if you need to extend the default `httpClient` methods with extra functionality, or replace it altogether.
236+
You can provide a custom `httpClient` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
237237

238238
```js
239239
import { client } from 'client/client.gen';
@@ -243,7 +243,7 @@ client.setConfig({
243243
});
244244
```
245245

246-
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom client to be.
246+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
247247

248248
## Plugins
249249

docs/openapi-ts/clients/angular/v19.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ const url = client.buildUrl<FooData>({
231231
console.log(url); // prints '/foo/1?bar=baz'
232232
```
233233

234-
## Custom `httpClient`
234+
## Custom Instance
235235

236-
You can implement your own `httpClient`. This is useful if you need to extend the default `httpClient` methods with extra functionality, or replace it altogether.
236+
You can provide a custom `httpClient` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
237237

238238
```js
239239
import { client } from 'client/client.gen';
@@ -243,7 +243,7 @@ client.setConfig({
243243
});
244244
```
245245

246-
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom client to be.
246+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
247247

248248
## Plugins
249249

docs/openapi-ts/clients/axios.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ const url = client.buildUrl<FooData>({
211211
console.log(url); // prints '/foo/1?bar=baz'
212212
```
213213

214-
## Custom `axios`
214+
## Custom Instance
215215

216-
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.
216+
You can provide a custom `axios` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
217217

218218
```js
219219
import axios from 'axios';

docs/openapi-ts/clients/fetch.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,32 @@ const response = await getFoo({
146146

147147
## Interceptors
148148

149-
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the id of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor
149+
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application.
150+
151+
They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the ID of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own.
152+
153+
### Example: Request interceptor
150154

151155
::: code-group
152156

153157
```js [use]
154158
import { client } from 'client/client.gen';
155-
// Supports async functions
159+
156160
async function myInterceptor(request) {
157161
// do something
158162
return request;
159163
}
164+
160165
interceptorId = client.interceptors.request.use(myInterceptor);
161166
```
162167

163168
```js [eject]
164169
import { client } from 'client/client.gen';
165170

166-
// eject interceptor by interceptor id
171+
// eject by ID
167172
client.interceptors.request.eject(interceptorId);
168173

169-
// eject interceptor by reference to interceptor function
174+
// eject by reference
170175
client.interceptors.request.eject(myInterceptor);
171176
```
172177

@@ -177,36 +182,38 @@ async function myNewInterceptor(request) {
177182
// do something
178183
return request;
179184
}
180-
// update interceptor by interceptor id
185+
186+
// update by ID
181187
client.interceptors.request.update(interceptorId, myNewInterceptor);
182188

183-
// update interceptor by reference to interceptor function
189+
// update by reference
184190
client.interceptors.request.update(myInterceptor, myNewInterceptor);
185191
```
186192

187193
:::
188194

189-
and an example response interceptor
195+
### Example: Response interceptor
190196

191197
::: code-group
192198

193199
```js [use]
194200
import { client } from 'client/client.gen';
201+
195202
async function myInterceptor(response) {
196203
// do something
197204
return response;
198205
}
199-
// Supports async functions
206+
200207
interceptorId = client.interceptors.response.use(myInterceptor);
201208
```
202209

203210
```js [eject]
204211
import { client } from 'client/client.gen';
205212

206-
// eject interceptor by interceptor id
213+
// eject by ID
207214
client.interceptors.response.eject(interceptorId);
208215

209-
// eject interceptor by reference to interceptor function
216+
// eject by reference
210217
client.interceptors.response.eject(myInterceptor);
211218
```
212219

@@ -217,17 +224,18 @@ async function myNewInterceptor(response) {
217224
// do something
218225
return response;
219226
}
220-
// update interceptor by interceptor id
227+
228+
// update by ID
221229
client.interceptors.response.update(interceptorId, myNewInterceptor);
222230

223-
// update interceptor by reference to interceptor function
231+
// update by reference
224232
client.interceptors.response.update(myInterceptor, myNewInterceptor);
225233
```
226234

227235
:::
228236

229237
::: tip
230-
To eject, you must provide the id or reference of the interceptor passed to `use()`, the id is the value returned by `use()` and `update()`.
238+
To eject, you must provide the ID or reference of the interceptor passed to `use()`, the ID is the value returned by `use()` and `update()`.
231239
:::
232240

233241
## Auth
@@ -281,9 +289,9 @@ const url = client.buildUrl<FooData>({
281289
console.log(url); // prints '/foo/1?bar=baz'
282290
```
283291

284-
## Custom `fetch`
292+
## Custom Instance
285293

286-
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.
294+
You can provide a custom `fetch` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
287295

288296
```js
289297
import { client } from 'client/client.gen';
@@ -295,7 +303,7 @@ client.setConfig({
295303
});
296304
```
297305

298-
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
306+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
299307

300308
## API
301309

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,32 @@ const response = await getFoo({
130130

131131
## Interceptors
132132

133-
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the id of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own. Below is an example request interceptor
133+
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application.
134+
135+
They can be added with `use`, removed with `eject`, and updated wth `update`. The `use` and `update` methods will return the ID of the interceptor for use with `eject` and `update`. Fetch API does not have the interceptor functionality, so we implement our own.
136+
137+
### Example: Request interceptor
134138

135139
::: code-group
136140

137141
```js [use]
138142
import { client } from 'client/client.gen';
139-
// Supports async functions
143+
140144
async function myInterceptor(request) {
141145
// do something
142146
return request;
143147
}
148+
144149
interceptorId = client.interceptors.request.use(myInterceptor);
145150
```
146151

147152
```js [eject]
148153
import { client } from 'client/client.gen';
149154

150-
// eject interceptor by interceptor id
155+
// eject by ID
151156
client.interceptors.request.eject(interceptorId);
152157

153-
// eject interceptor by reference to interceptor function
158+
// eject by reference
154159
client.interceptors.request.eject(myInterceptor);
155160
```
156161

@@ -161,36 +166,38 @@ async function myNewInterceptor(request) {
161166
// do something
162167
return request;
163168
}
164-
// update interceptor by interceptor id
169+
170+
// update by ID
165171
client.interceptors.request.update(interceptorId, myNewInterceptor);
166172

167-
// update interceptor by reference to interceptor function
173+
// update by reference
168174
client.interceptors.request.update(myInterceptor, myNewInterceptor);
169175
```
170176

171177
:::
172178

173-
and an example response interceptor
179+
### Example: Response interceptor
174180

175181
::: code-group
176182

177183
```js [use]
178184
import { client } from 'client/client.gen';
185+
179186
async function myInterceptor(response) {
180187
// do something
181188
return response;
182189
}
183-
// Supports async functions
190+
184191
interceptorId = client.interceptors.response.use(myInterceptor);
185192
```
186193

187194
```js [eject]
188195
import { client } from 'client/client.gen';
189196

190-
// eject interceptor by interceptor id
197+
// eject by ID
191198
client.interceptors.response.eject(interceptorId);
192199

193-
// eject interceptor by reference to interceptor function
200+
// eject by reference
194201
client.interceptors.response.eject(myInterceptor);
195202
```
196203

@@ -201,17 +208,18 @@ async function myNewInterceptor(response) {
201208
// do something
202209
return response;
203210
}
204-
// update interceptor by interceptor id
211+
212+
// update by ID
205213
client.interceptors.response.update(interceptorId, myNewInterceptor);
206214

207-
// update interceptor by reference to interceptor function
215+
// update by reference
208216
client.interceptors.response.update(myInterceptor, myNewInterceptor);
209217
```
210218

211219
:::
212220

213221
::: tip
214-
To eject, you must provide the id or reference of the interceptor passed to `use()`, the id is the value returned by `use()` and `update()`.
222+
To eject, you must provide the ID or reference of the interceptor passed to `use()`, the ID is the value returned by `use()` and `update()`.
215223
:::
216224

217225
## Auth
@@ -264,9 +272,9 @@ const url = client.buildUrl<FooData>({
264272
console.log(url); // prints '/foo/1?bar=baz'
265273
```
266274

267-
## Custom `fetch`
275+
## Custom Instance
268276

269-
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.
277+
You can provide a custom `fetch` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
270278

271279
```js
272280
import { client } from 'client/client.gen';
@@ -278,7 +286,7 @@ client.setConfig({
278286
});
279287
```
280288

281-
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
289+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
282290

283291
## API
284292

docs/openapi-ts/clients/nuxt.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ const url = client.buildUrl<FooData>({
243243
console.log(url); // prints '/foo/1?bar=baz'
244244
```
245245

246-
## Custom `$fetch`
246+
## Custom Instance
247247

248-
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.
248+
You can provide a custom `$fetch` instance. This is useful if you need to extend the default instance with extra functionality, or replace it altogether.
249249

250250
```js
251251
import { client } from 'client/client.gen';
@@ -257,7 +257,7 @@ client.setConfig({
257257
});
258258
```
259259

260-
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be.
260+
You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be.
261261

262262
## API
263263

0 commit comments

Comments
 (0)