https://github.com/js-bits/fetch
Cross-environment (nodejs/web) fetch API
https://github.com/js-bits/fetch
Last synced: about 1 year ago
JSON representation
Cross-environment (nodejs/web) fetch API
- Host: GitHub
- URL: https://github.com/js-bits/fetch
- Owner: js-bits
- Created: 2021-06-26T21:15:37.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-19T03:09:19.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T08:16:44.224Z (about 1 year ago)
- Language: JavaScript
- Size: 890 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cross-environment (nodejs/web) fetch APi
This package exports `window.fetch` object in a browser and [node-fetch](https://www.npmjs.com/package/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:
```javascript
import fetch from '@js-bits/fetch';
```
or require for CommonJS:
```javascript
const fetch = require('@js-bits/fetch');
```
## How to use
```javascript
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
```
## Notes
- The package versions are aligned with [node-fetch](https://www.npmjs.com/package/node-fetch) versions.
- [version 2](https://www.npmjs.com/package/@js-bits/fetch/v/2.0.0) of this package supports [version 2](https://github.com/node-fetch/node-fetch/tree/2.x#readme) of [node-fetch](https://www.npmjs.com/package/node-fetch).
- Minimal size (bytes) in a browser since [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is natively supported. Does not include any polyfills.