fetch-interceptors

0.1.1 • Public • Published

fetch() Response Interceptors

Wrap JavaScript's fetch() to add response interceptors.

import withInterceptors from 'fetch-interceptors'
 
const wrappedFetch = withInterceptors(
  fetch,
  ({ request, ...response }) => {
    return {
      ...response,
      // moar props
    }
  },
  response => {
    // 🤒
    return response
  }
)
 
wrappedFetch('https://httpbin.org/get?foo=bar')
  .then(response => {
    console.log(response)
    // { "foo": "bar" }
  })

Readme

Keywords

none

Package Sidebar

Install

npm i fetch-interceptors

Weekly Downloads

40

Version

0.1.1

License

MIT

Unpacked Size

4.56 kB

Total Files

9

Last publish

Collaborators

  • johnnynotsolucky