fetch-intercept
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 fetch
compatible environment or added a appropriate polyfill.
import fetchIntercept from 'fetch-intercept';
const unregister = fetchIntercept.register({
request: function (url, config) {
return [url, config];
},
requestError: function (error) {
return Promise.reject(error);
},
response: function (response) {
return response;
},
responseError: function (error) {
return Promise.reject(error);
}
});
fetch('http://google.com');
unregister();
React-Native Compatibility
Support react-native 0.17
or higher versions.
License
MIT