# @httpland/request-utils

> Request utility collection

Latest version **1.0.0** (published 2023-05-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @httpland/request-utils
pnpm add @httpland/request-utils
yarn add @httpland/request-utils
bun add @httpland/request-utils
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-05-09 |
| First published | 2023-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | miyauci |
| Keywords | http, request, fetch-api, utility, utilities, collection |

## Links

- npm: https://www.npmjs.com/package/@httpland/request-utils
- Repository: https://github.com/httpland/request-utils
- Issues: https://github.com/httpland/request-utils/issues
- npm.io page: https://npm.io/package/@httpland/request-utils

## Dependencies (2)

- [@miyauci/isx](https://npm.io/package/@miyauci/isx.md) 1.3.1
- [@httpland/headers-utils](https://npm.io/package/@httpland/headers-utils.md) 1.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-05-09
- 1.0.0-beta.1 (beta) — 2023-05-09

## README

# request-utils

[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/request_utils)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/httpland/request-utils)](https://github.com/httpland/request-utils/releases)
[![codecov](https://codecov.io/github/httpland/request-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/httpland/request-utils)
[![GitHub](https://img.shields.io/github/license/httpland/request-utils)](https://github.com/httpland/request-utils/blob/main/LICENSE)

[![test](https://github.com/httpland/request-utils/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/request-utils/actions/workflows/test.yaml)
[![NPM](https://nodei.co/npm/@httpland/request-utils.png?mini=true)](https://nodei.co/npm/@httpland/request-utils/)

Request utility collection.

## equalsRequest

Check two `Request` fields equality.

```ts
import { equalsRequest } from "https://deno.land/x/request_utils@$VERSION/equal.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

declare const url: URL;

assert(
  equalsRequest(
    new Request(url, { method: "HEAD" }),
    new Request(url, { method: "HEAD" }),
  ),
);
```

If you also want to check the equivalence of the body, set the mode to strict.

```ts
import { equalsRequest } from "https://deno.land/x/request_utils@$VERSION/equal.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

declare const url: URL;

assert(
  await equalsRequest(
    new Request(url, { body: "", method: "POST" }),
    new Request(url, { body: "", method: "POST" }),
    true,
  ),
);
```

### Throwing error

In strict mode, if request body has already been read.

```ts
import { equalsRequest } from "https://deno.land/x/request_utils@$VERSION/equal.ts";
import { assert, assertThrows } from "https://deno.land/std/testing/asserts.ts";

declare const url: URL;
const request = new Request(url, { body: "" });
await request.text();

assert(request.bodyUsed);
assertThrows(() => equalsRequest(request, request, true));
```

## isRequest

Whether the input is `Request` or not.

```ts
import { isRequest } from "https://deno.land/x/request_utils@$VERSION/is.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(isRequest(new Request("http://localhost")), true);
assertEquals(isRequest({}), false);
assertEquals(isRequest(null), false);
```

## withHeader

Return an instance with the provided `Request` replacing the specified header.

There are no side effects on the original `Request`.

```ts
import { withHeader } from "https://deno.land/x/request_utils@$VERSION/with_header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

declare const init: Request;
declare const fieldName: string;
declare const fieldValue: string;

const request = withHeader(init, fieldName, fieldValue);

assert(request.headers.get(fieldName), fieldValue);
assert(init !== request);
```

## API

All APIs can be found in the [deno doc](https://deno.land/x/request_utils?doc).

## License

Copyright © 2023-present [httpland](https://github.com/httpland).

Released under the [MIT](./LICENSE) license

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