@ianwalter/http

A convenience wrapper around the fetch API

Usage no npm install needed!

<script type="module">
  import ianwalterHttp from 'https://cdn.skypack.dev/@ianwalter/http';
</script>

README

@ianwalter/http

A convenience wrapper around the fetch API

npm page

Installation

pnpm 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