sunset-header-interceptor
v0.1.2
Published
[The Sunset HTTP Header draft](https://tools.ietf.org/html/draft-wilde-sunset-header-05)
Downloads
4
Maintainers
Readme
Axios Sunset Header Interceptor
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 */ })
👋