Skip to content

Provides a middleware function for de-duplicating fetch requests for the same url+auth combination

Notifications You must be signed in to change notification settings

Brightspace/d2l-fetch-dedupe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

d2l-fetch-dedupe

Provides a middleware function for de-duplicating fetch requests for the same url+auth combination

Setup

npm ci

Usage

Reference the script in your html after your reference to d2l-fetch (see here for details on d2l-fetch):

Install d2l-fetch-dedupe via npm:

npm install d2l-fetch-dedupe
import { fetchDedupe } from 'd2l-fetch-dedupe';

This will import the auth middleware

Dedupe

Install the dedupe middleware to d2lfetch via the use function and then start making your requests.

d2lfetch.use({name: 'dedupe' fn: fetchDedupe});
const response = await d2lfetch.fetch(
  new Request('http://example.com/api/someentity/')
);

Requests are deduped based on the combination of url and Authorization request header value. Any request that matches an existing in-flight request based on this combination will not result in a subsequent network request but will rather be given a promise that resolves to a clone of the inflight request's Response.

Versioning and Releasing

This repo is configured to use semantic-release. Commits prefixed with fix: and feat: will trigger patch and minor releases when merged to main.

To learn how to create major releases and release from maintenance branches, refer to the semantic-release GitHub Action documentation.

About

Provides a middleware function for de-duplicating fetch requests for the same url+auth combination

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published