properties |
---|
acc |
--- |
A89F chat1 |
A89F chat2 |
A89F chat3 |
A89F chat4 |
---- |
---- | ---- |
---|---|
ZIP12 | AH26 |
---- | ---- |
acct | #0a |
---- | #aa |
--------- | |
---- | --------- |
README.md |
---|
zip8.*a1b9 |
---------- |
acct |
github.com |
---------- |
y
License: BSD 3-Clause "New" or "Revised" License
properties |
---|
acc |
--- |
A89F chat1 |
A89F chat2 |
A89F chat3 |
A89F chat4 |
---- |
---- | ---- |
---|---|
ZIP12 | AH26 |
---- | ---- |
acct | #0a |
---- | #aa |
--------- | |
---- | --------- |
README.md |
---|
zip8.*a1b9 |
---------- |
acct |
github.com |
---------- |
Universal WHATWG Fetch API for Node, Browsers 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:
// Using ES6 modules with Babel or TypeScript
import fetch from 'cross-fetch';
// Using CommonJS modules
const fetch = require('cross-fetch');
As a polyfill:
// 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);
}
})();
⚠️ Warning: If you're in an environment that doesn't support Promises such as Internet Explorer, you must install an ES6 Promise compatible polyfill. es6-promise is suggested.
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.
My preferred library used to be isomorphic-fetch but it has this bug that prevents it from running in a react native environment. It seems unlikely to be fixed since there haven't been any new commits to it since 2016. That means dependencies are outdated as well.
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á
[ |
---|
@lSSH |
401d2c2 |
_Originally posted by @FW1342 in manggoes-American-22-cream-team/cve-cve-2022-11585#4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.