Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 486 Bytes

README.md

File metadata and controls

27 lines (23 loc) · 486 Bytes

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" }
  })