@js-bits/fetch
v3.1.4
Published
Cross-environment (nodejs/web) fetch API
Downloads
373
Maintainers
Readme
Cross-environment (nodejs/web) fetch APi
This package exports window.fetch
object in a browser and node-fetch module in a Node.js environment. Which is helpful when you develop a package compatible with both environments and use fetch
for HTTP requests. Allows to avoid conditional imports.
Installation
Install with npm:
npm install @js-bits/fetch
Install with yarn:
yarn add @js-bits/fetch
Import where you need it:
import fetch from '@js-bits/fetch';
or require for CommonJS:
const fetch = require('@js-bits/fetch');
How to use
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
Notes
- The package versions are aligned with node-fetch versions.
- version 2 of this package supports version 2 of node-fetch.
- Minimal size (bytes) in a browser since Fetch API is natively supported. Does not include any polyfills.