The Fej instance to use for tracking
Configuration options
Middleware function
import { createFej, createCancellationMiddleware } from 'fej';
const api = createFej();
api.use('cancellation', createCancellationMiddleware(api));
// Requests are now automatically tracked
const response = await api.fej('/api/data');
api.use('cancellation', createCancellationMiddleware(api, {
tags: ['dashboard', 'high-priority'],
}));
// Later: cancel all dashboard requests
api.abortRequestsByTag('dashboard');
api.use('cancellation', createCancellationMiddleware(api, {
onCancel: (requestId, ctx) => {
console.log(`Request ${requestId} was cancelled`);
},
}));
Create a cancellation middleware that automatically tracks requests
Creates middleware that automatically tracks requests using AbortController, enabling cancellation via the Fej instance methods.