https://github.com/bcomnes/fetch-undici
Isomorphic fetch with window.fetch and undici.fetch
https://github.com/bcomnes/fetch-undici
browser fetch isomorphic node universal
Last synced: 11 months ago
JSON representation
Isomorphic fetch with window.fetch and undici.fetch
- Host: GitHub
- URL: https://github.com/bcomnes/fetch-undici
- Owner: bcomnes
- License: mit
- Created: 2021-09-06T21:25:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-05-06T00:01:44.000Z (about 1 year ago)
- Last Synced: 2025-07-08T14:09:19.686Z (12 months ago)
- Topics: browser, fetch, isomorphic, node, universal
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/fetch-undici
- Size: 153 KB
- Stars: 20
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# fetch-undici
[](https://github.com/bcomnes/fetch-undici/actions)
**Justs use fetch directly in node or browsers. It just works now! Remember to use undici.request in node only contexts. Its much faster!**
Isomorphic exports of `fetch`, providing [`window.fetch`][br] in the browser, and [`undici.fetch`][ud] in node.js.
```
npm install fetch-undici
```
## Usage
``` js
import {
fetch,
Headers,
Response,
Request
} from 'fetch-undici';
```
## Why
If you want to write an API client of some kind, that would be useful in the browser or in Node.js, `fetch-undici` provides the best implementation of `fetch` for the environment it's used in.
## How
`fetch-undici` works by utilizing environment specific exports fields so that you can have dependency injection at the built-in node module resolver layer.
It supports the following export fields:
- `main` (cjs node)
- `browser` (cjs browser)
- `exports.node` (cjs node)
- `exports.browser` (esm browser)
## License
MIT
[br]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
[ud]: https://github.com/nodejs/undici