JSPM

frisbee-intercept

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q35477F
  • License MIT

Package Exports

  • frisbee-intercept

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (frisbee-intercept) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

frisbee-intercept

Codelab

Create Interceptors for your frisbee APIs so you can add headers to requests and pre-process the server reponses.

Getting Started

Prerequisites

As its name implies, frisbee should be installed to intercept its requests. Follow the Installation steps in their repository.

Installing

NPM

npm install --save  frisbee-intercept

Usage

import Frisbee from 'frisbee';
import FrisbeeAPIInterceptor from 'frisbee-intercept'

// create a new instance of Frisbee 
const myAPI = new Frisbee({
    baseURI: "http://myBaseURI.com.eg/",
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
});

//Create an intereption wrapper arround your API
var myAPIInterceptor = FrisbeeAPIInterceptor(myAPI);

//register your interceptor with your API, ** you can register as many interceptors as you want to your api **
const unregister = myAPIInterceptor.register({
    request: function (url, config) {
        // Modify the url or config here
        return [url, config];
    },

    requestError: function (error) {
        // Called when an error occured during another 'request' interceptor call
        return Promise.reject(error);
    },

    response: function (response) {
        // Modify the reponse object
        //Handle Forbidden status code

        return response;
    },

    responseError: function (error) {
        // Handle an fetch error
        return Promise.reject(error);

    }
});

//make your requests to see interception in action
myAPI.post("Account/Login", { body: {} });

// Unregister your interceptor
unregister();

Credits