big-fetch

1.0.11 • Public • Published

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

  • abort(): Set the current promise to rejected
  • 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🌈

Package Sidebar

Install

npm i big-fetch

Weekly Downloads

12

Version

1.0.11

License

ISC

Unpacked Size

3.39 kB

Total Files

4

Last publish

Collaborators

  • cecilxx