Skip to content

docs: clarify when to install undici vs using Node's built-in fetch#4868

Open
travisbreaks wants to merge 1 commit intonodejs:mainfrom
travisbreaks:docs/undici-vs-builtin-fetch
Open

docs: clarify when to install undici vs using Node's built-in fetch#4868
travisbreaks wants to merge 1 commit intonodejs:mainfrom
travisbreaks:docs/undici-vs-builtin-fetch

Conversation

@travisbreaks
Copy link

This relates to...

#4066

Changes

While PR #4245 added an "Undici vs. Fetch" section to the README, this PR adds a dedicated best-practices guide page within the docsify documentation site, making the information discoverable from the docs sidebar.

The new guide at docs/docs/best-practices/undici-vs-builtin-fetch.md covers:

  • Background: How Node.js bundles undici to power its built-in fetch, Request, Response, Headers, and FormData globals
  • When you do NOT need to install undici: Standard Fetch API usage on Node.js v18+, zero-dependency scenarios, cross-runtime libraries
  • When you SHOULD install undici: Advanced APIs (request, stream, pipeline), connection pooling (Client, Pool, BalancedPool), proxy support (ProxyAgent), testing/mocking (MockAgent), interceptors, or getting a newer version than what Node.js bundles
  • Version compatibility table: Which undici version ships with which Node.js release
  • How to override the built-in fetch with the installed version
  • Further reading links to relevant API docs

Also adds the guide to the docsify sidebar under "Best Practices" (first entry, as the issue requested it be "near the top").

Status

Co-authored-by: Egger egger@horny-toad.com

Adds a best-practices doc page explaining when to install undici from
npm versus relying on Node.js's built-in fetch. Covers advanced APIs,
connection pooling, proxy support, mocking, interceptors, and version
compatibility. Also adds a sidebar link so the guide is discoverable
in the docs site.

Closes nodejs#4066

Co-authored-by: Egger <egger@horny-toad.com>
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just smaller details

If all of the following are true, you can rely on the built-in globals and skip
adding undici to your dependencies:

- You only need the standard Fetch API (`fetch`, `Request`, `Response`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to add the desire of having cross-platform interoperability (browsers + runtimes)


### Proxy support

`ProxyAgent` and `EnvHttpProxyAgent` handle HTTP(S) proxying, which is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvHttpProxyAgent is currently supported by native fetch.

|---|---|---|
| v18.x | ~5.x | `fetch` is experimental (behind `--experimental-fetch` in early v18) |
| v20.x | ~6.x | `fetch` is stable |
| v22.x | ~6.x / ~7.x | `fetch` is stable |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add v24?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants