https://github.com/ianwalter/http
A convenience wrapper around the fetch API
https://github.com/ianwalter/http
fetch http
Last synced: 9 months ago
JSON representation
A convenience wrapper around the fetch API
- Host: GitHub
- URL: https://github.com/ianwalter/http
- Owner: ianwalter
- License: other
- Created: 2018-09-21T13:32:34.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-10-17T16:53:38.000Z (over 2 years ago)
- Last Synced: 2025-04-30T03:49:29.964Z (9 months ago)
- Topics: fetch, http
- Language: JavaScript
- Homepage:
- Size: 5.33 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @ianwalter/http
> A convenience wrapper around the [fetch][fetchUrl] API
[![npm page][npmImage]][npmUrl]
## Installation
```console
yarn add @ianwalter/http
```
## Usage
```js
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
```js
http.after = (url, init, response) => ({
...response,
ok: false,
status: 401,
statusText: 'Unauthorized'
})
```
## License
Apache 2.0 with Commons Clause - See [LICENSE][licenseUrl]
Created by [Ian Walter](https://iankwalter.com)
[fetchUrl]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
[npmImage]: https://img.shields.io/npm/v/@ianwalter/http.svg
[npmUrl]: https://www.npmjs.com/package/@ianwalter/http
[licenseUrl]: https://github.com/ianwalter/http/blob/main/LICENSE