Skip to content

Commit

Permalink
docs(fetch): add differences between Undici fetch and standard Fetch API
Browse files Browse the repository at this point in the history
  • Loading branch information
asrar211 committed Dec 20, 2024
1 parent 84a9f85 commit 53496ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/docs/api/Fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ const busboy = new Busboy({

Readable.fromWeb(response.body).pipe(busboy)
```

## Differences Between Undici's Fetch and the Standard Fetch API

The `fetch` implementation in Undici is inspired by the Fetch API standard but has some key differences:

1. **`new Response(asyncIterable)`**:
- Undici extends the standard `Response` constructor to accept an `asyncIterable` as its body. This allows streams and other async sources to be directly used. This feature is not part of the Fetch API in browsers.

2. **Cookies Handling**:
- Unlike browsers, Undici does not automatically manage cookies. In browsers, cookies are managed through the `Cookie` header and automatically sent with requests. In Undici, you need to manually handle cookies.

3. **No Forbidden Headers**:
- In browsers, some headers (e.g., `User-Agent`, `Referer`) are restricted from being modified for security reasons. In Undici, these headers can be freely set.

4. **Environment-Specific Behavior**:
- Undici operates outside of a browser environment, so browser-specific features like Service Workers and Cache API are unavailable.

For a complete reference, see the [WHATWG Fetch Standard](https://fetch.spec.whatwg.org/).

0 comments on commit 53496ac

Please sign in to comment.