Gathering detailed insights and metrics for whatwg-fetch-ie8
Gathering detailed insights and metrics for whatwg-fetch-ie8
Gathering detailed insights and metrics for whatwg-fetch-ie8
Gathering detailed insights and metrics for whatwg-fetch-ie8
A window.fetch polyfill.(fork from github/fetch and simple support for ie8.)
npm install whatwg-fetch-ie8
Typescript
Module System
Node Version
NPM Version
JavaScript (89.98%)
Shell (4.61%)
HTML (4.25%)
Makefile (1.16%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
401 Commits
1 Forks
2 Branches
1 Contributors
Updated on May 04, 2016
Latest Version
1.0.0
Package Id
whatwg-fetch-ie8@1.0.0
Size
6.35 kB
NPM Version
2.15.0
Node Version
4.4.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
6
This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to uphold this code. [code-of-conduct]: http://todogroup.org/opencodeofconduct/#fetch/opensource@github.com
The global fetch
function is an easier way to make web requests and handle
responses than using an XMLHttpRequest. This polyfill is written as closely as
possible to the standard Fetch specification at https://fetch.spec.whatwg.org.
Available on Bower as fetch.
1$ bower install fetch
You'll also need a Promise polyfill for older browsers.
1$ bower install es6-promise
This can also be installed with npm
.
1$ npm install whatwg-fetch --save
For a node.js implementation, try node-fetch.
For use with webpack, refer to Using WebPack with shims and polyfills.
For babel and es2015+, make sure to import the file:
1import 'whatwg-fetch'; 2fetch(...);
The fetch
function supports any HTTP method. We'll focus on GET and POST
example requests.
1fetch('/users.html') 2 .then(function(response) { 3 return response.text() 4 }).then(function(body) { 5 document.body.innerHTML = body 6 })
1fetch('/users.json') 2 .then(function(response) { 3 return response.json() 4 }).then(function(json) { 5 console.log('parsed json', json) 6 }).catch(function(ex) { 7 console.log('parsing failed', ex) 8 })
1fetch('/users.json').then(function(response) { 2 console.log(response.headers.get('Content-Type')) 3 console.log(response.headers.get('Date')) 4 console.log(response.status) 5 console.log(response.statusText) 6})
1var form = document.querySelector('form') 2 3fetch('/users', { 4 method: 'POST', 5 body: new FormData(form) 6})
1fetch('/users', { 2 method: 'POST', 3 headers: { 4 'Accept': 'application/json', 5 'Content-Type': 'application/json' 6 }, 7 body: JSON.stringify({ 8 name: 'Hubot', 9 login: 'hubot', 10 }) 11})
1var input = document.querySelector('input[type="file"]') 2 3var data = new FormData() 4data.append('file', input.files[0]) 5data.append('user', 'hubot') 6 7fetch('/avatars', { 8 method: 'POST', 9 body: data 10})
The fetch
specification differs from jQuery.ajax()
in mainly two ways that
bear keeping in mind:
The Promise returned from fetch()
won't reject on HTTP error status
even if the response is a HTTP 404 or 500. Instead, it will resolve normally,
and it will only reject on network failure, or if anything prevented the
request from completing.
By default, fetch
won't send any cookies to the server, resulting in
unauthenticated requests if the site relies on maintaining a user session.
To have fetch
Promise reject on HTTP error statuses, i.e. on any non-2xx
status, define a custom response handler:
1function checkStatus(response) { 2 if (response.status >= 200 && response.status < 300) { 3 return response 4 } else { 5 var error = new Error(response.statusText) 6 error.response = response 7 throw error 8 } 9} 10 11function parseJSON(response) { 12 return response.json() 13} 14 15fetch('/users') 16 .then(checkStatus) 17 .then(parseJSON) 18 .then(function(data) { 19 console.log('request succeeded with JSON response', data) 20 }).catch(function(error) { 21 console.log('request failed', error) 22 })
To automatically send cookies for the current domain, the credentials
option
must be provided:
1fetch('/users', { 2 credentials: 'same-origin' 3})
This option makes fetch
behave similar to XMLHttpRequest with regards to
cookies. Otherwise, cookies won't get sent, resulting in these requests not
preserving the authentication session.
Use the include
value to send cookies in a cross-origin resource sharing (CORS) request.
1fetch('https://example.com:1234/users', { 2 credentials: 'include' 3})
Like with XMLHttpRequest, the Set-Cookie
response header returned from the
server is a forbidden header name and therefore can't be programatically
read with response.headers.get()
. Instead, it's the browser's responsibility
to handle new cookies being set (if applicable to the current URL). Unless they
are HTTP-only, new cookies will be available through document.cookie
.
Due to limitations of XMLHttpRequest, the response.url
value might not be
reliable after HTTP redirects on older browsers.
The solution is to configure the server to set the response HTTP header
X-Request-URL
to the current URL after any redirect that might have happened.
It should be safe to set it unconditionally.
1# Ruby on Rails controller example 2response.headers['X-Request-URL'] = request.url
This server workaround is necessary if you need reliable response.url
in
Firefox < 32, Chrome < 37, Safari, or IE.
![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|
Latest ✔ | Latest ✔ | 10+ ✔ | Latest ✔ | 6.1+ ✔ |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/25 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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