cross-fetch
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "cross-fetch", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Universal WHATWG Fetch API for Node, Browsers and React Native", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/lquixada/cross-fetch", |
@@ -14,3 +14,2 @@ cross-fetch | ||
- **Updated**: lastest version of whatwg-fetch and node-fetch used | ||
- **Small**: 2.5kb gzipped | ||
@@ -73,6 +72,7 @@ | ||
As a [ponyfill](https://github.com/sindresorhus/ponyfill): | ||
With [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise): | ||
```javascript | ||
const fetch = require('cross-fetch'); | ||
import fetch from 'cross-fetch'; | ||
// Or just: import 'cross-fetch/polyfill'; | ||
@@ -88,20 +88,29 @@ fetch('//api.github.com/users/lquixada') | ||
console.log(user); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
``` | ||
As a polyfill: | ||
With [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function): | ||
```javascript | ||
require('cross-fetch'); | ||
import fetch from 'cross-fetch'; | ||
// Or just: import 'cross-fetch/polyfill'; | ||
fetch('//api.github.com/users/lquixada') | ||
.then(res => { | ||
(async () => { | ||
try { | ||
const res = await fetch('//api.github.com/users/lquixada'); | ||
if (res.status >= 400) { | ||
throw new Error("Bad response from server"); | ||
} | ||
return res.json(); | ||
}) | ||
.then(user => { | ||
const user = await res.json(); | ||
console.log(user); | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
})(); | ||
``` | ||
@@ -144,2 +153,3 @@ | ||
* [graphql-request](https://github.com/graphcool/graphql-request) | ||
* [Swagger](https://swagger.io/) | ||
@@ -146,0 +156,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64569
179