# fetch-addons

> A collection of addons for the fetch API

Latest version **1.3.0** (published 2024-09-11) · MIT license · 32.6K weekly downloads

## Install

```sh
npm install fetch-addons
pnpm add fetch-addons
yarn add fetch-addons
bun add fetch-addons
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score; growing popularity.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-09-11 |
| First published | 2023-07-05 |
| Weekly downloads | 32.6K |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Stephan Meijer |
| Maintainers | smeijer |
| Keywords | fetch, fetch-api, fetch-addons, fetch-helpers, fetch-utils, curl, fetch-to-curl |

## Links

- npm: https://www.npmjs.com/package/fetch-addons
- Repository: https://github.com/smeijer/fetch-addons
- Homepage: https://github.com/smeijer/fetch-addons#readme
- Issues: https://github.com/smeijer/fetch-addons/issues
- Funding: https://github.com/smeijer/fetch-addons?sponsor=1
- npm.io page: https://npm.io/package/fetch-addons

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2024-09-11
- 1.2.0 — 2024-05-17
- 1.1.0 — 2023-07-07
- 1.0.2 — 2023-07-05
- 1.0.1 — 2023-07-05
- 1.0.0 — 2023-07-05

## README

# Fetch Addons

> A collection of addons for the fetch API.

## Install

```sh
npm install fetch-addons
```

## Usage

```js
import * as addons from 'fetch-addons';
```

### toCurl

Serializes a `Request` object to a cURL command. Handy for logging and replaying failed requests.

```js
import { toCurl } from 'fetch-addons';

// fetch(input, init)
toCurl(input, init);
toCurl(request);

// curl --url 'https://example.com' \
//   --request 'POST' \
//   --header 'content-type: application/json' \
//   --data '{"foo":"bar"}'`
```

### getRequest

Get a `Request` object from `RequestInit`.

```js
import { getRequest } from 'fetch-addons';

// fetch(input, init);
const request = getRequest(input, init);
const request = getRequest(request);
```

### getHeaders

Get a `Headers` object from `HeadersInit`.

```js
import { getHeaders } from 'fetch-addons';

// fetch(input, init);
const headers = getHeaders(init.headers);

fetch('https://example.com').then((response) => {
	const headers = getHeaders(response.headers);
});
```

### deleteEmptyHeaders

Delete empty headers from a `Headers` object.

```js
import { deleteEmptyHeaders } from 'fetch-addons';

const request = new Request('https://example.com', {
	headers: {
		'content-type': 'application/json',
		'x-1': '',
		'x-2': 'undefined',
		'x-3': 'null',
	},
});

deleteEmptyHeaders(request.headers);
// Headers { 'content-type': 'application/json' }
```

---
_Source: https://npm.io/package/fetch-addons · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
