Skip to content

Repository files navigation

fetch-intercept

Build Status

Interceptor library for the native fetch command inspired by angular http interceptors.

fetch-intercept monkey patches the global fetch method and allows you the usage in Browser, Node and Webworker environments.

Installation

npm install fetch-intercept --save

Usage

Note: You need to require fetch-intercept before you use fetch the first time.

Make sure you have a fetchcompatible environment or added a appropriate polyfill.

importfetchInterceptfrom'fetch-intercept';constunregister=fetchIntercept.register({request: function(url,config){// Modify the url or config herereturn[url,config];},requestError: function(error){// Called when an error occured during another 'request' interceptor callreturnPromise.reject(error);},response: function(response){// Modify the reponse objectreturnresponse;},responseError: function(error){// Handle an fetch errorreturnPromise.reject(error);}});// Call fetch to see your interceptors in action.fetch('http://google.com');// Unregister your interceptorunregister();

React-Native Compatibility

Support react-native 0.17 or higher versions.

License

MIT

About

Interceptor library for the native fetch command inspired by angular http intercepts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages