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
Copy file name to clipboardexpand all lines: README.md
+56-48
Original file line number
Diff line number
Diff line change
@@ -25,16 +25,16 @@ Import:
25
25
26
26
```js
27
27
// ESM / Typescript
28
-
import { ofetch } from'ofetch'
28
+
import { ofetch } from"ofetch";
29
29
30
30
// CommonJS
31
-
const { ofetch } =require('ofetch')
31
+
const { ofetch } =require("ofetch");
32
32
```
33
33
34
34
## ✔️ Works with Node.js
35
35
36
36
We use [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) to detect Node.js
37
-
and automatically use [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).
37
+
and automatically use [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).
38
38
39
39
### `keepAlive` support
40
40
@@ -47,7 +47,7 @@ By setting the `FETCH_KEEP_ALIVE` environment variable to `true`, an http/https
47
47
`ofetch` will smartly parse JSON and native values using [destr](https://github.com/unjs/destr), falling back to text if it fails to parse.
48
48
49
49
```js
50
-
const { users } =awaitofetch('/api/users')
50
+
const { users } =awaitofetch("/api/users");
51
51
```
52
52
53
53
For binary content types, `ofetch` will instead return a `Blob` object.
@@ -56,21 +56,24 @@ You can optionally provide a different parser than destr, or specify `blob`, `ar
`ofetch` automatically stringifies request body (if an object is passed) and adds JSON `Content-Type` and `Accept` headers (for `put`, `patch` and `post` requests).
By using `baseURL` option, `ofetch` prepends it with respecting to trailing/leading slashes and query search params for baseURL using [ufo](https://github.com/unjs/ufo):
140
143
141
144
```js
142
-
awaitofetch('/config', { baseURL })
145
+
awaitofetch("/config", { baseURL });
143
146
```
144
147
145
148
## ✔️ Adding Query Search Params
146
149
147
150
By using `query` option (or `params` as alias), `ofetch` adds query search params to URL by preserving query in request itself using [ufo](https://github.com/unjs/ufo):
0 commit comments