Quickstart

Quickstart: Replace a hard-coded price table with live data

Replacing a stale hand-maintained price table with live API data is low-risk if you fetch behind a flag, diff first, then cut over. 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

feature flagCut over safely
diff firstCompare before trusting
fallbackKeep the static copy

Fetch behind a flag

Add the live catalogue fetch behind a feature flag so you can enable it for a fraction of traffic and watch for issues before a full cut-over.

Diff against your static table

const live = (await fetch(`${BASE}/products`).then(r => r.json())).data;
const drift = live.filter(l => static[l.id]?.max_amount !== l.max_amount);
if (drift.length) console.warn('price table was stale:', drift);

The diff usually reveals your static table had drifted — which is exactly why you are moving to live data.

Keep the static copy as a fallback

Retain the old table as the fallback when the fetch fails, so a transient API issue never leaves the reader with no figures at all.

Frequently asked questions

Is it risky to go live?

Not if you flag it, diff against your existing values first, and keep the static table as a fallback. You cut over only once the live data checks out.

Why keep the static values?

As a fallback for transient failures. Live data is the source of truth, but a cached or static copy prevents an empty table during an outage.

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.