sunset-header-interceptor

0.1.2 • Public • Published

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 */ })

👋

Package Sidebar

Install

npm i sunset-header-interceptor

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

6.5 kB

Total Files

9

Last publish

Collaborators

  • johnnynotsolucky