Skip to content

Coalesces multiple calls to fetch() for the same URL into a single network request.

License

Notifications You must be signed in to change notification settings

cinema6/fetch-coalesce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Aug 2, 2016
633cd19 · Aug 2, 2016

History

12 Commits
Aug 2, 2016
Aug 2, 2016
Aug 1, 2016
Aug 1, 2016
Aug 1, 2016
Aug 1, 2016
Aug 1, 2016
Aug 1, 2016
Aug 1, 2016
Aug 2, 2016
Aug 2, 2016
Aug 2, 2016

Repository files navigation

fetch-coalesce

fetch-coalesce is a decorator that coalesces multiple equivalent fetch() calls into a single network request.

Install

$> npm install fetch-coalesce --save

Example

import coalesce from 'fetch-coalesce';

const fetch = coalesce({ methods: ['GET', 'HEAD'] })(window.fetch);

fetch('/foo/bar');
fetch('/foo/bar');
// Only one network request is made.

Usage

import coalesce from 'fetch-coalesce';

coalesce(config) => decorator(fetch) => decorated

  • Function that accepts configuration and returns a fetch decorator Function.
  • Parameters
    • (Object) config [optional]:
      • (String[]) config.methods [optional]: HTTP methods (GET, PUT, POST, etc.) that should be coalesced. By default, all idempotent methods are coalesced.
  • Returns
    • (Function): A fetch decorator Function:
      • Parameters
        • (Function) fetch: The fetch Function to decorate. Should pretty much always be window.fetch.
      • Returns
        • (Function): The decorated fetch Function. Call it just like you would call fetch().

About

Coalesces multiple calls to fetch() for the same URL into a single network request.

Resources

License

Stars

Watchers

Forks

Packages

No packages published