Deduplication Middleware
Coalesce identical in-flight requests into a single fetch
Basic Usage
import { dedupe } from '@cleverbrush/client/dedupe';
const client = createClient(api, {
middlewares: [dedupe()],
});
// These fire only ONE fetch — both callers receive the same response
const [a, b] = await Promise.all([
client.todos.list(),
client.todos.list(),
]);Options
| Option | Type | Default |
|---|---|---|
methods | string[] | ['GET'] |
key | (url, init) => string | method + url |
Only GET requests are deduplicated by default. Mutations (POST, PUT, etc.) always go through. Provide a custom keyfunction to control what counts as a "duplicate".