dedupeInFlightRequestsMiddleware

Source
import { dedupeInFlightRequestsMiddleware } from "@prestojs/rest";
dedupeInFlightRequestsMiddleware(options)

Middleware that will dedupe simultaneous identical in flight requests. All requests that are matched as duplicates will all resolve to the same value with only a single fetch call having occured.

To use this globally set the following somewhere that executes when your app starts:

Endpoint.defaultConfig.middleware = [
dedupeInFlightRequestsMiddleware(),
];
ParameterTypeDescription
options.getKey
Function

Function to get a key for a request. If the key matches another in flight request then it is considered a duplicate. The default implementation includes the URL, the request method and all request headers in the key.

The key can be anything (object, string, number) - it will be compared deeply to existing keys for a match.

options.test
Function

Function to test whether a request is subject to de-duping. The default implementation only de-dupes requests with method set to GET.

Function

Middleware function to pass to Endpoint or set on Endpoint.defaultConfig.middleware