🎣 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 completesInstall with npm:
npm install --save http-hookOr yarn:
yarn add http-hookOr 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>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()