Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.55 KB

readme.md

File metadata and controls

71 lines (52 loc) · 1.55 KB

🎣 http-hook

Fast hooks for modifying
HTTP requests and responses.



import httpHook from 'http-hook'

httpHook.attach({
  request: req => { ... },
  response: res => { ... }
})

fetch() // request modified before sending
  .then() // response modified after request completes

Installation

Install with npm:

npm install --save http-hook

Or yarn:

yarn add http-hook

Or using a script tag like this example in CodeSandbox:

<script
  src="https://unpkg.com/http-hook@^0.1/lib/index.umd.js"
  crossorigin="anonymous"
></script>

Usage

By default, when you attach request or response hooks then the native fetch and XMLHttpRequest variables are overwritten to make the hooks affect all HTTP requests.

If you don't want to overwrite the globals, then you can pass in { globals: false } and use packaged variables:

import httpHook from 'http-hook'

httpHook.attach({
  globals: false,
  request: req => { ... },
  response: res => { ... }
})

httpHook.fetch()

new httpHook.XMLHttpRequest()