http

A convenience wrapper around the fetch API

OTHER License

Downloads
75
Stars
4
Committers
5

@ianwalter/http

A convenience wrapper around the fetch API

Installation

yarn add @ianwalter/http

Usage

import { http } from '@ianwalter/http'

// Add a new header to the global http instance.
http.options.headers = { 'csrf-token': 'abc123' }

// Send a POST request with some data.
const response = await http.post('/api/thing', { body: { complete: true } })

Intercepting requests and responses

http.after = (url, init, response) => ({
  ...response,
  ok: false,
  status: 401,
  statusText: 'Unauthorized'
})

License

Apache 2.0 with Commons Clause - See LICENSE

 

Created by Ian Walter