0.1.1 • Published 5 years ago

http-hook v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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:

<script
  src="https://unpkg.com/http-hook@0.1.0/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
0.1.1

5 years ago

0.1.0

5 years ago