Quickstart

Quickstart: Rate-limit your own widget's API usage

A busy page can flood the API on its own; debounce writes, cache reads and coalesce duplicate in-flight calls to stay a good citizen. This recipe gives you the exact code, uses only the unauthenticated public ring, and links to the endpoints and the application flow so the reader always has a next step.

2 min read

debounceOne quote per pause
coalesceShare in-flight calls
cacheReads served locally

Coalesce duplicate requests

const inflight = new Map();
function dedupe(key, fn) {
  if (inflight.has(key)) return inflight.get(key);
  const promise = fn().finally(() => inflight.delete(key));
  inflight.set(key, promise);
  return promise;
}
// two components asking for products share one call
dedupe('products', () => fetch(`${BASE}/products`).then(r => r.json()));

Debounce and cache

Debounce the quote calls so a slider fires once per pause, and cache the catalogue so multiple widgets on a page share one fetch. Together these keep even a heavy page comfortably under the limit.

Frequently asked questions

Can one page trip the rate limit?

A naive widget with a live slider can. Debounce writes, cache reads and coalesce duplicate in-flight requests and you will stay well within the limit.

What is request coalescing?

When two parts of the page ask for the same data at once, you make one request and share the promise, rather than firing two identical calls.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.