big-fetch
v1.0.11
Published
big fetch will return a primose with a abort function and can set a timeout
Downloads
17
Maintainers
Readme
Big Fetch
The big-fetch is a wrapper based on fetch and promise, adding abort and timeout functions. If you like it, please give me your star👼. thx~~~🚀
Features
- [x] abort(): Set the current promise to rejected
- [x] timeout: Increase timeout for current request
- [ ] onprogress: progress function
Browser Support
The big-fetch is a wrapper based on fetch and promise, If your browser does not support fetch and promise you need to install whatwg-fetch and promise-polyfill
NPM Install
npm install big-fetch --save-exact
Example
A basic fetch request is really simple to set up. Have a look at the following code:
import bigFetch from 'big-fetch'
bigFetch('http://example.com/movies.json')
.then(function(response) {
return response.json()
})
.then(function(myJson) {
console.log(myJson)
})
Instead of passing a path to the resource you want to request into the fetch() call, you can create a request object using the Request() constructor, and pass that in as a fetch() method argument:
import bigFetch from 'big-fetch'
var myHeaders = new Headers()
var myInit = {
method: 'GET',
headers: myHeaders,
mode: 'cors',
cache: 'default',
timeout: 10000 // set 10000ms timeout
}
var request = bigFecth('flowers.jpg', options)
request
.then(data => {
console.log(data)
})
.catch(error => {
console.error(error)
})
// cancel
request.abort()
Issues
☺️Welcome to issues and discuss🌈