0.1.2 ā€¢ Published 6 years ago

sunset-header-interceptor v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Axios Sunset Header Interceptor

The Sunset HTTP Header draft

Fetch Interceptor

import sunsetInterceptor from 'sunset-header-interceptor'

const sunsetHandler = (response, sunset, extra) = {
  // Soon Thomas won't be really useful anymore.
}

fetch('https://foo.com/bar', { /* init props */ })
  .then(sunsetInterceptor(sunsetHandler))
  .then(...)

With fetch-interceptors

import fetchInterceptors = from 'fetch-interceptors'
import sunsetInterceptor from 'sunset-header-interceptor'

const sunsetHandler = (response, sunset, extra) = {
  // Soon Thomas won't be really useful anymore.
}

const myFetch = fetchInterceptors(fetch, sunsetInterceptor(sunsetHandler))

myFetch('https://httpbin.org/get?foo=bar', { /* init props */ )

Axios

import sunsetInterceptor from 'sunset-header-interceptor'

const sunsetHandler = (response, sunset, extra) = {
  // Soon Thomas won't be really useful anymore.
}

axios.interceptors.response.use(sunsetInterceptor(sunsetHandler))

Roll your own

import interceptor from 'sunset-header-interceptor/interceptor'

const myDankSunsetInterceptor = interceptor(( // Extract headers from an arb response
  response // Response object returned by your HTTP request library
) => {
  return ... // Logic to extract header information from the response
}, ( // Sunset header handler, called if Sunset header found
  response, // Response from teh HTTP request if available
  sunset, // Date representing Thomas' inevitable demise
  { link, params } // link URI, and whatever other params were passed through
) => {
  // Tell someone about Thomas.
  // Note: Anything returned from here is thrown away. Like Thomas.
});

myDankSunsetInterceptor({ /* reponse data */ })

šŸ‘‹