Skip to content
/ fetch Public

A fetch implementation supporting progress events, cancellable calls and timeout

License

Notifications You must be signed in to change notification settings

herzaso/fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xfetch

The fetch API is a great replacement for XHR, allowing for a more modern usage with Promises. However, once you start using it, you realize that there are some features that are missing from the implementation, and this is where this implementation comes in.

this implementation is an opinionated fetch polyfill (XHR fallback) that enables progress events, cancellable calls, timeouts and ETag support.

Installation

NPM

npm install --save xfetch

Usage

Progress handlers are defined the same as in XHR. The handlers are passed to fetch in the options object by defining onProgress and onUploadProgress.

function onProgress(event) {
  if (event.lengthComputable) {
    var percent = Math.floor((event.loaded / event.total) * 100);
    console.log(percent);
  }
}

fetch('http://some.api/', { onProgress });

License

This code is provided under MIT license, basically allowing you to do anything with it but without warranty of any kind.

Notice

This package is incomplete, as it is a work in progress.

Suggestions, comments and help will be greatly appreciated.

About

A fetch implementation supporting progress events, cancellable calls and timeout

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published