# @digitalbazaar/http-client

> An opinionated, isomorphic HTTP client.

Latest version **4.4.0** (published 2026-08-06) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @digitalbazaar/http-client
pnpm add @digitalbazaar/http-client
yarn add @digitalbazaar/http-client
bun add @digitalbazaar/http-client
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.4.0 |
| Published | 2026-08-06 |
| First published | 2020-06-18 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=18.0 |
| Dependencies | 2 |
| Unpacked size | 26.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Digital Bazaar, Inc. |
| Maintainers | dlongley, msporny, davidlehn, gannan |
| Keywords | http, isomorphic, http client |

## Links

- npm: https://www.npmjs.com/package/@digitalbazaar/http-client
- Repository: https://github.com/digitalbazaar/http-client
- Issues: https://github.com/digitalbazaar/http-client/issues
- npm.io page: https://npm.io/package/@digitalbazaar/http-client

## Dependencies (2)

- [ky](https://npm.io/package/ky.md) ^1.14.3
- [undici](https://npm.io/package/undici.md) ^6.28.0

## Recent versions

- 4.4.0 (latest) — 2026-08-06
- 4.3.0 — 2026-01-15
- 4.2.0 — 2025-03-26
- 4.1.1 — 2024-02-21
- 4.1.0 — 2024-01-26
- 4.0.0 — 2023-09-12
- 3.4.1 — 2023-04-29
- 3.4.0 — 2023-04-14
- 3.3.0 — 2023-01-17
- 3.2.0 — 2022-05-19
- 3.1.0 — 2022-05-03
- 3.0.1 — 2022-04-26
- 3.0.0 — 2022-04-20
- 2.0.1 — 2021-12-02
- 2.0.0 — 2021-11-15
- … 3 more at https://npm.io/package/@digitalbazaar/http-client/versions

## README

# http-client
An opinionated, isomorphic HTTP client for Node.js, browsers, and React Native.

### Usage

#### Import httpClient (Node.js, browsers, or React Native)
```js
import {httpClient} from '@digitalbazaar/http-client';
```

#### Import and initialize a custom Bearer Token client
```js
import {httpClient} from '@digitalbazaar/http-client';

const accessToken = '12345';
const headers = {Authorization: `Bearer ${accessToken}`};

const client = httpClient.extend({headers});

// subsequent http calls will include an 'Authorization: Bearer 12345' header
```

#### Disable self-signed TLS/SSL cert checks for development purposes only
```js
import {Agent} from 'https';
import {httpClient} from '@digitalbazaar/http-client';

const agent = new https.Agent({rejectUnauthorized: false});
const client = httpClient.extend({headers, agent});

// subsequent http calls will use the provided https Agent
```

#### GET a JSON response in the browser
```js
try {
  const response = await httpClient.get('http://httpbin.org/json');
  return response.data;
} catch(e) {
  // status is HTTP status code
  // data is JSON error from the server
  const {data, status} = e;
  throw e;
}
```

#### GET a JSON response in Node with an HTTP Agent
```js
import https from 'https';
// use an agent to avoid self-signed certificate errors
const agent = new https.Agent({rejectUnauthorized: false});
try {
  const response = await httpClient.get('http://httpbin.org/json', {agent});
  return response.data;
} catch(e) {
  // status is HTTP status code
  // data is JSON error from the server if available
  const {data, status} = e;
  throw e;
}
```

#### GET HTML by overriding default headers
```js
const headers = {Accept: 'text/html'};
try {
  const response = await httpClient.get('http://httpbin.org/html', {headers});
  // see: https://developer.mozilla.org/en-US/docs/Web/API/Response#methods
  return response.text();
} catch(e) {
  // status is HTTP status code
  // any message from the server can be parsed from the response if present
  const {response, status} = e;
  throw e;
}
```

#### POST a JSON payload
```js
try {
  const response = await httpClient.post('http://httpbin.org/json', {
    // `json` is the payload or body of the POST request
    json: {some: 'data'}
  });
  return response.data;
} catch(e) {
  // status is HTTP status code
  // data is JSON error from the server
  const {data, status} = e;
  throw e;
}
```

#### POST a JSON payload in Node with an HTTP Agent
```js
import https from 'https';
// use an agent to avoid self-signed certificate errors
const agent = new https.Agent({rejectUnauthorized: false});
try {
  const response = await httpClient.post('http://httpbin.org/json', {
    agent,
    // `json` is the payload or body of the POST request
    json: {some: 'data'}
  });
  return response.data;
} catch(e) {
  // status is HTTP status code
  // data is JSON error from the server
  const {data, status} = e;
  throw e;
}
```

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