Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Node Fetch | 8,461 | 219,668 | 33,659 | 14 days ago | 94 | July 25, 2023 | 188 | mit | JavaScript | |
A light-weight module that brings the Fetch API to Node.js | ||||||||||
Graphql Yoga | 7,748 | 1,462 | 232 | a day ago | 2,084 | June 28, 2023 | 75 | mit | TypeScript | |
🧘 Rewrite of a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience. The core of Yoga implements WHATWG Fetch API and can run/deploy on any JS environment. | ||||||||||
Isomorphic Fetch | 6,936 | 185,206 | 7,659 | 7 months ago | 23 | September 23, 2020 | 54 | mit | JavaScript | |
Isomorphic WHATWG Fetch API, for Node & Browserify | ||||||||||
Fetch | 2,023 | 15 days ago | 243 | other | HTML | |||||
Fetch Standard | ||||||||||
Cross Fetch | 1,587 | 14,308 | 4,914 | 2 months ago | 49 | July 03, 2023 | 10 | mit | JavaScript | |
Universal WHATWG Fetch API for Node, Browsers and React Native. | ||||||||||
Frisbee | 1,120 | 72 | 19 | 10 months ago | 62 | July 10, 2020 | n,ull | mit | JavaScript | |
:dog2: Modern fetch-based alternative to axios/superagent/request. Great for React Native. | ||||||||||
Xr | 454 | 60 | 7 | 3 years ago | 31 | January 25, 2021 | 2 | mit | TypeScript | |
Ultra-lightweight wrapper around XMLHttpRequest. You should probably use fetch (whatwg-fetch) or RxJS, though. | ||||||||||
Fets | 361 | 6 hours ago | 22 | mit | TypeScript | |||||
TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience | ||||||||||
Undici Fetch | 244 | 2 years ago | 9 | July 06, 2021 | mit | JavaScript | ||||
A WHATWG Fetch implementation based on @nodejs/undici | ||||||||||
Fetch Ponyfill | 219 | 1,878 | 340 | 2 years ago | 22 | January 19, 2021 | 2 | mit | JavaScript | |
WHATWG fetch ponyfill |
Universal WHATWG Fetch API for Node, Browsers, Workers and React Native. The scenario that cross-fetch really shines is when the same JavaScript codebase needs to run on different platforms.
npm install --save cross-fetch
As a ponyfill (imports locally):
// Using ES6 modules with Babel or TypeScript
import fetch from 'cross-fetch';
// Using CommonJS modules
const fetch = require('cross-fetch');
As a polyfill (installs globally):
// Using ES6 modules
import 'cross-fetch/polyfill';
// Using CommonJS modules
require('cross-fetch/polyfill');
The CDN build is also available on unpkg:
<script src="//unpkg.com/cross-fetch/dist/cross-fetch.js"></script>
This adds the fetch function to the window object. Note that this is not UMD compatible.
With promises:
import fetch from 'cross-fetch';
// Or just: import 'cross-fetch/polyfill';
fetch('//api.github.com/users/lquixada')
.then(res => {
if (res.status >= 400) {
throw new Error("Bad response from server");
}
return res.json();
})
.then(user => {
console.log(user);
})
.catch(err => {
console.error(err);
});
With async/await:
import fetch from 'cross-fetch';
// Or just: import 'cross-fetch/polyfill';
(async () => {
try {
const res = await fetch('//api.github.com/users/lquixada');
if (res.status >= 400) {
throw new Error("Bad response from server");
}
const user = await res.json();
console.log(user);
} catch (err) {
console.error(err);
}
})();
You can find a comprehensive doc at Github's fetch page. If you want to play with cross-fetch, check our JSFiddle playground.
Tip: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around.
I did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements.
In a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on sindresorhus's ponyfill page. It's up to you if you're fine with it or not.
Just like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the node-fetch library, if you're in a browser or React Native, it delivers you the github's whatwg-fetch. The same strategy applies whether you're using polyfill or ponyfill.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
The New York Times | Apollo GraphQL | Swagger | VulcanJS | graphql-request |
Heavily inspired by the works of matthew-andrews. Kudos to him!
cross-fetch is licensed under the MIT license Leonardo Quixad
@lquixada |