Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
response-iterator
Creates an async iterator for a variety of inputs in the browser and node. Supports fetch, node-fetch, and cross-fetch
@fetch-impl/cross-fetch
User Configurable Fetch Implementation. cross-fetch adapter.
@based/fetch
CF worker compatible cross-fetch
retry-my-fetch
It's a decorator for `Fetch` API ([fetch](https://fetch.spec.whatwg.org/), [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [cross-fetch](https://github.com/lquixada/cross-fetch), etc.) which allows resending (retrying) your reques
Universal WHATWG Fetch API for Node, Browsers and React Native.
npm install cross-fetch
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,671 Stars
666 Commits
105 Forks
13 Watching
5 Branches
19 Contributors
Updated on 27 Nov 2024
JavaScript (53%)
TypeScript (31.2%)
HTML (8.47%)
Makefile (3.74%)
Shell (3.59%)
Cumulative downloads
Total Downloads
Last day
-1.8%
3,263,106
Compared to previous day
Last week
4.2%
17,395,993
Compared to previous week
Last month
10.1%
71,631,578
Compared to previous month
Last year
19.5%
805,031,219
Compared to previous year
1
30
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.
1npm install --save cross-fetch
As a ponyfill (imports locally):
1// Using ES6 modules with Babel or TypeScript 2import fetch from 'cross-fetch'; 3 4// Using CommonJS modules 5const fetch = require('cross-fetch');
As a polyfill (installs globally):
1// Using ES6 modules 2import 'cross-fetch/polyfill'; 3 4// Using CommonJS modules 5require('cross-fetch/polyfill');
The CDN build is also available on unpkg:
1<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:
1import fetch from 'cross-fetch'; 2// Or just: import 'cross-fetch/polyfill'; 3 4fetch('//api.github.com/users/lquixada') 5 .then(res => { 6 if (res.status >= 400) { 7 throw new Error("Bad response from server"); 8 } 9 return res.json(); 10 }) 11 .then(user => { 12 console.log(user); 13 }) 14 .catch(err => { 15 console.error(err); 16 });
With async/await:
1import fetch from 'cross-fetch'; 2// Or just: import 'cross-fetch/polyfill'; 3 4(async () => { 5 try { 6 const res = await fetch('//api.github.com/users/lquixada'); 7 8 if (res.status >= 400) { 9 throw new Error("Bad response from server"); 10 } 11 12 const user = await res.json(); 13 14 console.log(user); 15 } catch (err) { 16 console.error(err); 17 } 18})();
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 |
The latest stable version of the package.
Stable Version
2
6.1/10
Summary
Incorrect Authorization in cross-fetch
Affected Versions
< 2.2.6
Patched Versions
2.2.6
6.1/10
Summary
Incorrect Authorization in cross-fetch
Affected Versions
>= 3.0.0, < 3.1.5
Patched Versions
3.1.5
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
binaries present in source code
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More