A set of higher-order functions for the WHATWG Fetch API, providing composable middleware such as JSON handling, query string injection, timeout, retry (via vercel/fetch-retry), and JWT token support. Version 1.0.1 is the latest stable release, last updated in 2020. It re-exports cross-fetch for cross-platform compatibility (browser, Node, React Native) and includes TypeScript definitions. Key differentiators: opinionated default configuration via createFetch(), first-class JWT support with token refresh and request retry, and a functional composition approach inspired by higher-order functions.
npm install fetch-composeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a composed fetch with default middleware (JSON, query, throw on non-ok, timeout) and shows usage with options like query parameters and JSON body.
Update imports to use camelCase with uppercase JSON: import { withJSON } from 'fetch-compose'Pass custom timeout via withTimeout: createFetch({ timeout: 5000 }) or use withTimeout(fetch, 5000)Ensure provider implements refreshToken() if you want automatic retry on 401 responses.
Consider using only native fetch on modern Node.js versions, or explicitly import cross-fetch directly.
Use import { fetch } from 'fetch-compose' (named import) instead of import fetch from 'fetch-compose'.Ensure you are using fetch-compose which polyfills AbortController via abortcontroller-polyfill, or install it separately.
Increase timeout with withTimeout(fetch, 30000) or adjust default in createFetch({ timeout: 30000 }).