Skip to content
AF
Cookbook

The Fitness API Cookbook

Runnable reference implementations of the patterns the rest of this site documents in prose: rotation-safe token refresh, webhook ingestion that survives duplicates and reordering, and rate-limit handling that degrades instead of hammering. Every recipe is dependency-free JavaScript with an injected clock, fetch, and store, ships with a node:test suite, and runs in CI on every change — the code on each page is a byte-verbatim copy of the file that passed. Read the theory on the linked pages; take the working version from here.

The theory lives in Troubleshooting, Architecture, and Testing — each recipe links its source pages. MIT-licensed; adapt freely.

Auth & API clients

The failure modes that break every user at once.

Data ingestion

Webhooks and backfills that survive duplicates, reordering, and outages.

Correctness & motion

The rollup that survives DST, and the rep counter that earns its counts.

Frequently asked questions

How is the cookbook code tested?
Every recipe ships with a node:test suite in the same directory, and a CI workflow runs the full suite on every change to the cookbook — the code you see on a recipe page is a byte-verbatim copy of the file that passed. Tests inject fakes for the clock, fetch, and storage, so they exercise the logic (races, rotations, retries, DST transitions) without any network or provider account.
Can I use these recipes in a commercial product?
Yes — the cookbook files are MIT-licensed, stated in each file's header. They are deliberately dependency-free and built around injected interfaces (store, fetch, clock), so adapting one usually means implementing a small store interface against your database and deleting the in-memory reference version. Attribution is appreciated, not required.
Why does the cookbook avoid npm dependencies entirely?
Because reference code you can read end-to-end in one file is worth more than a cleverer implementation you cannot audit. Zero dependencies means no supply-chain surface, no version drift against your stack, and no framework assumptions — every recipe is plain modern JavaScript on Node 20+, portable into TypeScript or another runtime by hand without untangling a dependency tree.

All 24 questions in Cookbook, answered