# fetch-har

> Make a fetch request from a HAR definition

Latest version **12.0.4** (published 2026-06-02) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 65/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 12.0.4 |
| Published | 2026-06-02 |
| First published | 2017-10-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 2 |
| Unpacked size | 57.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | gkoberger, domharrington, mjcuva, jonursenbach, rafegoldberg, dannobytes, darrenyong, uppal101 |

## Links

- npm: https://www.npmjs.com/package/fetch-har
- Repository: https://github.com/readmeio/fetch-har
- Homepage: https://github.com/readmeio/fetch-har#readme
- Issues: https://github.com/readmeio/fetch-har/issues
- npm.io page: https://npm.io/package/fetch-har

## Dependencies (2)

- [@readme/data-urls](https://npm.io/package/@readme/data-urls.md) ^4.0.2
- [@types/har-format](https://npm.io/package/@types/har-format.md) ^1.2.13

## Recent versions

- 12.0.4 (latest) — 2026-06-02
- 12.0.3 — 2026-05-27
- 12.0.2 — 2026-04-28
- 12.0.1 — 2026-04-07
- 12.0.0 — 2026-04-06
- 11.1.1 — 2024-06-21
- 11.1.0 — 2023-11-08
- 11.0.1 — 2023-09-27
- 11.0.0 — 2023-09-27
- 10.0.0 — 2023-09-11
- 9.0.0 — 2023-06-01
- 8.1.5 — 2023-01-23
- 8.1.4 — 2023-01-03
- 8.1.3 — 2022-07-29
- 8.1.2 — 2022-07-27
- … 32 more at https://npm.io/package/fetch-har/versions

## README

# fetch-har

Make a [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) request from a HAR definition.

[![CI](https://github.com/readmeio/fetch-har/workflows/CI/badge.svg)](https://github.com/readmeio/fetch-har/)
[![](https://img.shields.io/npm/v/fetch-har)](https://npm.im/fetch-har)
[![License](https://img.shields.io/npm/l/fetch-har.svg)](LICENSE)

[![](https://raw.githubusercontent.com/readmeio/.github/main/oss-header.png)](https://readme.io)

## Features

- Supports Node 18+
- Natively works in all browsers that support [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) without having to use any polyfills.
- [Tested](https://github.com/readmeio/fetch-har/actions) across Chrome, Safari, Firefox on Mac, Windows, and Linux.
- Requests can be mocked with HTTP mocking libraries like [`nock`](https://npm.im/nock), [`msw`](https://npm.im/msw), or [`fetch-mock`](https://npm.im/fetch-mock).

## Installation

```
npm install --save fetch-har
```

## Usage

```js
import fetchHAR from 'fetch-har';

const har = {
  log: {
    entries: [
      {
        request: {
          headers: [
            {
              name: 'Authorization',
              value: 'Bearer api-key',
            },
            {
              name: 'Content-Type',
              value: 'application/json',
            },
          ],
          queryString: [
            { name: 'a', value: 1 },
            { name: 'b', value: 2 },
          ],
          postData: {
            mimeType: 'application/json',
            text: '{"id":8,"category":{"id":6,"name":"name"},"name":"name"}',
          },
          method: 'POST',
          url: 'http://httpbin.org/post',
        },
      },
    ],
  },
};

fetchHAR(har)
  .then(res => res.json())
  .then(console.log);
```

### API

#### Options

##### userAgent

A custom `User-Agent` header to apply to your request. Please note that browsers have their own handling for these headers in `fetch()` calls so it may not work everywhere; it will always be sent in Node however.

```js
await fetchHAR(har, { userAgent: 'my-client/1.0' });
```

##### files

An optional object map you can supply to use for `multipart/form-data` file uploads in leu of relying on if the HAR you have has [data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). It supports Node file buffers and the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) API.

```js
await fetchHAR(har, {
  files: {
    'owlbert.png': await fs.readFile('./owlbert.png'),
    'file.txt': document.querySelector('#some-file-input').files[0],
  },
});
```

If you don't supply this option `fetch-har` will fallback to the data URL present within the supplied HAR. If no `files` option is present, and no data URL (via `param.value`) is present in the HAR, a fatal exception will be thrown.

##### init

This optional argument lets you supply any option that's available to supply to the [Request constructor](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).

```js
await fetchHAR(har, {
  init: {
    headers: new Headers({
      'x-custom-header': 'buster',
    }),
  },
});
```

> [!CAUTION]
> If you supply `body` or `credentials` to this option they may be overridden by what your HAR requires.

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