{"id":18427,"library":"http-client","title":"http-client","description":"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.","status":"active","version":"4.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/mjackson/http-client","tags":["javascript"],"install":[{"cmd":"npm install http-client","lang":"bash","label":"npm"},{"cmd":"yarn add http-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is recommended; CommonJS requires destructuring the require.","wrong":"const createFetch = require('http-client').createFetch","symbol":"createFetch","correct":"import { createFetch } from 'http-client'"},{"note":"base is a named export, not the default.","wrong":"import base from 'http-client'","symbol":"base","correct":"import { base } from 'http-client'"},{"note":"All exports are from the main package, no subpath imports.","wrong":"import { createStack } from 'http-client/middleware'","symbol":"createStack","correct":"import { createStack } from 'http-client'"}],"quickstart":{"code":"import { createFetch, base, accept, parse } from 'http-client'\n\nconst fetch = createFetch(\n  base('https://api.example.com'),\n  accept('application/json'),\n  parse('json')\n)\n\nfetch('/users/1')\n  .then(response => {\n    console.log(response.body) // parsed JSON\n  })\n  .catch(error => {\n    console.error('Request failed:', error)\n  })","lang":"typescript","description":"Creates a typed fetch client with base URL, Accept header, and JSON parsing middleware."},"warnings":[{"fix":"Install and import a polyfill like isomorphic-fetch before using http-client.","message":"Requires a global fetch polyfill (e.g., isomorphic-fetch) in environments without native fetch (e.g., older Node versions).","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Update to v4.x; replace 'headers' middleware with explicit 'accept' and 'auth' calls.","message":"Version 3.x dropped support for Node < 10 and removed deprecated middleware 'headers' in favor of 'accept' and 'auth'.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Place 'parse' after all middleware that modifies request headers.","message":"Middleware order matters; for example, 'parse' must come after middleware that sets response headers (like 'accept' or 'auth').","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use 'accept' and 'auth' middleware individually.","message":"The 'headers' middleware was deprecated in v3.0 and removed in v4.0.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install and import isomorphic-fetch: `import 'isomorphic-fetch'` before using http-client.","cause":"No global fetch implementation present (e.g., in Node.js without polyfill).","error":"TypeError: Failed to fetch"},{"fix":"Ensure each middleware imported correctly and is a function.","cause":"Passed an invalid middleware (e.g., undefined) to createFetch.","error":"Uncaught TypeError: middleware is not a function"},{"fix":"Add parse('json') middleware to the fetch client stack.","cause":"JSON parse middleware not applied before accessing response.body.","error":"Cannot read property 'body' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}