A TypeScript framework for composable fetch middlewares built on standard web APIs.
qfetch lets you compose reusable request/response processing logic around the native fetch API. Build fetch clients with retry logic, authorization, default headers, base URLs, and more through composable middleware.
import {
compose,
withRetryStatus,
withRetryAfter,
withHeaders,
withBaseUrl,
} from '@qfetch/qfetch';
const qfetch = compose(
withRetryStatus({ statuses: [500, 502, 503] }),
withRetryAfter(),
withHeaders({ 'Content-Type': 'application/json' }),
withBaseUrl('https://api.example.com')
)(fetch);
// Use like regular fetch with retry, headers, and base URL baked in
const response = await qfetch('/users');
compose() or left-to-right with pipeline()# Install everything (recommended)
npm install @qfetch/qfetch
# Or install individual packages
npm install @qfetch/core @qfetch/middleware-base-url
| Package | Description |
|---|---|
| @qfetch/qfetch | All-in-one package with core and all middlewares |
| @qfetch/core | Core middleware composition system |
| @qfetch/middlewares | Collection of all middlewares (without core) |
| Package | Description |
|---|---|
| @qfetch/middleware-authorization | Authorization header injection and 401 retry handling |
| @qfetch/middleware-base-url | Base URL resolution using standard URL constructor |
| @qfetch/middleware-headers | Default headers for requests |
| @qfetch/middleware-query-params | Query parameters for request URLs |
| @qfetch/middleware-response-error | Throw errors based on HTTP response status codes |
| @qfetch/middleware-retry-after | Server-directed retry timing (Retry-After header) |
| @qfetch/middleware-retry-status | Client-controlled retry based on status codes |
MIT