Registry / devops / extended-fetch

extended-fetch

JSON →
library2.0.0jsnpmunverified

A hackable, lightweight HTTP client built on the native fetch API, version 2.0.0. It offers a modular middleware system for request/response interception, support for abort signals and timeouts, and a tiny footprint (<4KB). Released as ESM + UMD with TypeScript types, it requires Node.js 16+ or 18+. Unlike axios or node-fetch, it has zero dependencies and fully leverages the native fetch available in modern Node.js and browsers.

npm install extended-fetch
INSTALL
IMPORT
SIG · EXTENDED-FETCH
E
extended-fetch
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

createHttpClient
import { createHttpClient } from 'extended-fetch'
import createHttpClient from 'extended-fetch'
The package exports only named exports; there is no default export.
initAuthMiddleware
import { initAuthMiddleware } from 'extended-fetch'
import { initAuthMiddleware } from 'extended-fetch/initAuthMiddleware'
initAuthMiddleware is exported from the main entry; no subpath import exists.
createHttpClient (require)
const { createHttpClient } = require('extended-fetch')
const createHttpClient = require('extended-fetch')
In CommonJS, destructure the require to get the named export.

Basic GET request using createHttpClient with baseUrl, error handling via catch on the Response object.

import { createHttpClient } from 'extended-fetch'; const api = createHttpClient({ baseUrl: process.env.API_BASE ?? '/' }); api.get('/users/1') .then((user) => console.log(user)) .catch(async (err) => { const { status, statusText } = err; console.error(`Error ${status}: ${statusText}`); });
Debug
Known issues
gotchaSince v2, the catch callback receives a pure Response instance, not an error with a formatted response. You must access response properties directly or call .formattedResponse if you want the parsed body.
fix
In catch, use the Response object: err.status, err.statusText, err.formattedResponse (if you need parsed body).
affects: >=2.0.0
breakingVersion 2.0.0 replaced the entire API; it is not backward compatible with v1.x. The library now only exports createHttpClient and initAuthMiddleware, and the HttpClient class is no longer exposed.
fix
Migrate from new HttpClient() to createHttpClient() and adjust middleware configuration to the new object shape.
affects: >=2.0.0
gotchaThe query parameter object is serialized using URLSearchParams; nested objects or arrays may not serialize as expected.
fix
Manually stringify complex query parameters or use flat key-value pairs.
affects: >=2.0.0
gotchaMiddleware handlers for 'request' must return a RequestInit or Promise<RequestInit>; forgetting to return will break the request chain.
fix
Ensure every request middleware returns the modified options object.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: api.get is not a function
Incorrect import: default import instead of named import.
fix
Use 'import { createHttpClient } from 'extended-fetch'' then call createHttpClient().
404 status but catch returns undefined
In v2, catch receives Response object; you must access .status explicitly.
fix
In catch: console.log(err.status, err.statusText);
request middleware not applied
Middleware object keys must be 'request' and 'response', not 'req'/'res'.
fix
Use { request: [...], response: [...] } in the config.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
extended-fetch — npm install extended-fetch · libregistry