Skip to content

usermirror/http-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🎣 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()

About

Fast hooks for modifying HTTP requests and responses

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published