Registry / http-networking / http-client

http-client

JSON →
library0.1.22jsnpmunverified

A lightweight library for composing HTTP clients using JavaScript's fetch API. Current stable version is 4.3.1, released with moderate cadence. It provides a middleware-based approach to extend and customize fetch behavior, supporting both client and server environments. Key differentiators include full preservation of fetch API capabilities, an extendable middleware API, and identical usage across Node.js and browsers. Unlike heavier alternatives like axios or superagent, http-client leans on the native fetch standard, allowing polyfills such as isomorphic-fetch for environments without global fetch.

npm install http-client
INSTALL
IMPORT
SIG · HTTP-CLIENT
H
http-client
http-networkingjavascriptv0.1.22
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createFetch
import { createFetch } from 'http-client'
const createFetch = require('http-client').createFetch
ESM import is recommended; CommonJS requires destructuring the require.
base
import { base } from 'http-client'
import base from 'http-client'
base is a named export, not the default.
createStack
import { createStack } from 'http-client'
import { createStack } from 'http-client/middleware'
All exports are from the main package, no subpath imports.

Creates a typed fetch client with base URL, Accept header, and JSON parsing middleware.

import { createFetch, base, accept, parse } from 'http-client' const fetch = createFetch( base('https://api.example.com'), accept('application/json'), parse('json') ) fetch('/users/1') .then(response => { console.log(response.body) // parsed JSON }) .catch(error => { console.error('Request failed:', error) })
Debug
Known issues
gotchaRequires a global fetch polyfill (e.g., isomorphic-fetch) in environments without native fetch (e.g., older Node versions).
fix
Install and import a polyfill like isomorphic-fetch before using http-client.
affects: >=1.0
breakingVersion 3.x dropped support for Node < 10 and removed deprecated middleware 'headers' in favor of 'accept' and 'auth'.
fix
Update to v4.x; replace 'headers' middleware with explicit 'accept' and 'auth' calls.
affects: >=3.0.0 <4.0.0
gotchaMiddleware order matters; for example, 'parse' must come after middleware that sets response headers (like 'accept' or 'auth').
fix
Place 'parse' after all middleware that modifies request headers.
affects: >=1.0
deprecatedThe 'headers' middleware was deprecated in v3.0 and removed in v4.0.
fix
Use 'accept' and 'auth' middleware individually.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: Failed to fetch
No global fetch implementation present (e.g., in Node.js without polyfill).
fix
Install and import isomorphic-fetch: `import 'isomorphic-fetch'` before using http-client.
Uncaught TypeError: middleware is not a function
Passed an invalid middleware (e.g., undefined) to createFetch.
fix
Ensure each middleware imported correctly and is a function.
Cannot read property 'body' of undefined
JSON parse middleware not applied before accessing response.body.
fix
Add parse('json') middleware to the fetch client stack.
Upgrade
Version history
0.1.22latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
http-client — npm install http-client · libregistry