Skip to content

itsfadnis/fetch-interceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

fetch-interceptor

Intercept fetch requests

Install

$ npm install --save fetch-interceptor

or

$ yarn add fetch-interceptor

Usage

const FetchInterceptor = require('fetch-interceptor');

// Register interceptor hooks
const interceptor = FetchInterceptor.register({
  onBeforeRequest(request, controller) {
    // Hook before request
  },
  onRequestSuccess(response, request, controller) {
    // Hook on response success
  },
  onRequestFailure(response, request, controller) {
    // Hook on response failure
  }
});

// Make fetch requests to see interceptor in action
fetch('http://whatever.com/whatever');

// Reset interceptor once you're done
interceptor.unregister();

Documentation

https://itsfadnis.github.io/fetch-interceptor