Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(fetch): add differences between Undici fetch and standard Fetch API #3968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/).