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

OptionTypeDefault
methodsstring[]['GET']
key(url, init) => stringmethod + 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".