Gathering detailed insights and metrics for fetch-ie8
Gathering detailed insights and metrics for fetch-ie8
Gathering detailed insights and metrics for fetch-ie8
Gathering detailed insights and metrics for fetch-ie8
npm install fetch-ie8
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
279 Stars
328 Commits
33 Forks
7 Watching
1 Branches
1 Contributors
Updated on 15 Jul 2024
Minified
Minified + Gzipped
JavaScript (89.04%)
HTML (5.08%)
Shell (4.03%)
Makefile (1.22%)
Ruby (0.64%)
Cumulative downloads
Total Downloads
Last day
-31.7%
1,320
Compared to previous day
Last week
-1.6%
8,172
Compared to previous week
Last month
26.5%
33,685
Compared to previous month
Last year
-7.4%
377,951
Compared to previous year
5
This fork supports IE8 with es5-shim, es5-sham and es6-promise.
If you also use JSONP, checkout fetch-jsonp.
Fetch API is still very new and not fully supported in some browsers, so you may
need to check browser verson as well as if window.fetch
exists. In this case,
you can set window.__disableNativeFetch = true
to use AJAX polyfill always.
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.
1$ npm install fetch-ie8 --save
You'll also need a Promise polyfill for older browsers.
1$ npm install es6-promise
Run this to polyfill the global environment at the beginning of your application.
1require('es6-promise').polyfill();
(For a node.js implementation, try node-fetch)
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('/query', { 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 form = new FormData() 4form.append('file', input.files[0]) 5form.append('user', 'hubot') 6 7fetch('/avatars', { 8 method: 'post', 9 body: form 10})
This causes fetch
to behave like jQuery's $.ajax
by rejecting the Promise
on HTTP failure status codes like 404, 500, etc. The response Promise
is
resolved only on successful, 200 level, status codes.
1function status(response) { 2 if (response.status >= 200 && response.status < 300) { 3 return response 4 } 5 throw new Error(response.statusText) 6} 7 8function json(response) { 9 return response.json() 10} 11 12fetch('/users') 13 .then(status) 14 .then(json) 15 .then(function(json) { 16 console.log('request succeeded with json response', json) 17 }).catch(function(error) { 18 console.log('request failed', error) 19 })
The Response
object has a URL attribute for the final responded resource.
Usually this is the same as the Request
url, but in the case of a redirect,
its all transparent. Newer versions of XHR include a responseURL
attribute
that returns this value. But not every browser supports this. The compromise
requires setting a special server side header to tell the browser what URL it
just requested (yeah, I know browsers).
1response.headers['X-Request-URL'] = request.url
If you want response.url
to be reliable, you'll want to set this header. The
day that you ditch this polyfill and use native fetch only, you can remove the
header hack.
Latest ✔ | Latest ✔ | 8+ ✔ | Latest ✔ | 6.1+ ✔ |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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 2024-11-25
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