
Security News
/Company News
Socket Is Sponsoring Composer and Packagist
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.
fetch-extras
Advanced tools
Useful utilities for working with Fetch
Build tiny, focused HTTP clients by composing only the features you need on top of the standard fetch API. No wrapper objects, no new interface to learn, no lock-in.
with* function adds a single capability. Stack them to build exactly the client you need.fetch — The input and output are always a plain fetch function. Your code stays portable and familiar.For a full-featured HTTP client on top of Fetch, check out my ky package.
npm install fetch-extras
import {
pipeline,
withTimeout,
withBaseUrl,
withHeaders,
withHttpError,
withJsonResponse,
} from 'fetch-extras';
// Create a tiny reusable API client that:
// - Times out after 5 seconds
// - Uses a base URL so you only write paths
// - Sends auth headers on every request
// - Throws errors for non-2xx responses
// - Parses JSON responses automatically
const apiFetch = pipeline(
fetch,
f => withTimeout(f, 5000),
f => withBaseUrl(f, 'https://api.example.com'),
f => withHeaders(f, {Authorization: 'Bearer token'}),
withHttpError,
withJsonResponse,
);
const data = await apiFetch('/users');
Listed in the recommended wrapping order for use with pipeline.
withTimeout - Abort requests that take too longwithBaseUrl - Resolve relative URLs against a base URLwithSearchParameters - Attach default query parameters to every requestwithHeaders - Attach default headers to every requestwithJsonBody - Auto-stringify plain objects as JSONwithRateLimit - Enforce client-side rate limiting with a sliding windowwithConcurrency - Cap how many requests can run simultaneouslywithDeduplication - Collapse concurrent identical GET requests into a single callwithCache - In-memory caching for plain unconditional GET responses with a TTLwithDownloadProgress - Track download progresswithUploadProgress - Track upload progresswithRetry - Retry failed requests with exponential backoffwithTokenRefresh - Auto-refresh auth tokens on 401 and retrywithHooks - beforeRequest and afterResponse hookswithHttpError - Throw on non-2xx responseswithJsonResponse - Parse response as JSON, with optional Standard Schema validation (place last in pipeline)pipeline - Compose with* wrappers without deep nestingpaginate - Async-iterate over paginated API endpointsthrowIfHttpError - Throw if a response is non-2xxHttpError - Error class for non-2xx responsesSchemaValidationError - Error class for schema validation failuresKy is a full-featured HTTP client with its own API (ky.get(), .json(), etc.). This package instead gives you individual utilities that wrap the standard fetch function. You pick only what you need and compose them together. If you want a batteries-included client, use Ky. If you want to stay close to the fetch API while adding specific capabilities, use this.
This package wraps the standard fetch API, so proxy support comes from the runtime. In Node.js, use the --use-env-proxy flag.
FAQs
Useful utilities for working with Fetch
The npm package fetch-extras receives a total of 14,595 weekly downloads. As such, fetch-extras popularity was classified as popular.
We found that fetch-extras demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Company News
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.

Research
/Security News
Benign-looking npm packages split malicious functionality across a dependency chain that deploys a cross-platform RAT targeting Alibaba developers.

Research
/Security News
Two Joyfill npm beta releases contain an import-time implant that uses blockchain transactions to retrieve a remote-access trojan.