Core framework for composable fetch middlewares.
Provides TypeScript types and composition utilities for building middleware that wraps the native fetch API. Create reusable request/response processing logic through a clean middleware pattern.
npm install @qfetch/core
import { compose, pipeline, type MiddlewareExecutor } from '@qfetch/core';
// Create a simple logging middleware
function withLogger(): MiddlewareExecutor {
return (next) => async (input, init) => {
console.log('Request:', input);
const response = await next(input, init);
console.log('Response:', response.status);
return response;
};
}
// Compose middlewares (right-to-left execution)
const qfetch = compose(
withLogger(),
// other middlewares...
)(fetch);
// Or use pipeline for left-to-right execution
const qfetch2 = pipeline(
withLogger(),
// other middlewares...
)(fetch);
await qfetch('https://api.example.com/users');
For complete API reference, examples, and type definitions, see the API documentation.