http-hook
v0.1.1
Published
Fast hooks for modifying HTTP requests and responses
Downloads
19
Readme
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 completesInstallation
Install with npm:
npm install --save http-hookOr yarn:
yarn add http-hookOr using a script tag:
<script
src="https://unpkg.com/[email protected]/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 global variables, then you can pass in { globals: false } and use the namespaced versions like this:
import httpHook from 'http-hook'
httpHook.attach({
globals: false,
request: req => { ... },
response: res => { ... }
})
httpHook.fetch()
httpHook.XMLHttpRequest