react-api-client
Skill0 starsChanged 21 days agoMITView on GitHub
Canonical axios API client + runtime config loader for the house React/Vite stack (JWT injection, X-Request-ID tracing, 401 refresh-and-retry, request deduplication, network retry with backoff, user-friendly error extraction). Use this whenever creating or editing a front-end API client, adding API calls to a new React project, fixing token-refresh/logout loops, wiring window.ENV_CONFIG runtime configuration, or when a project's api.ts/client.ts diverges from the standard — even if the user just says "hook the frontend to the backend".
- Reads credentials
- Installs packages
In this repository7 other files it gives its agents.
- deploy-cloudrunSkill
- gcp-bootstrapSkill
- gcp-migrate-dataSkill
- react-app-scaffoldSkill
- react-auth-otpSkill
- react-seo-ssgSkill
- stack-auditSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
If the backend lacks the refresh endpoint or {code, message} envelope, wire the shared backend packages first (fastapi-reqlog + the auth …
- Distinctive: line 50
When you improve the engine here, offer to propagate the change to the sibling projects.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
React API client (house stack)
The canonical front-end HTTP layer extracted from perfect-resume (the most evolved of the
three sibling projects — brandician and wine-your-sign have older mutations; wine's lacks
401-refresh and deduplication entirely). assets/ is the single source of truth: copy the
files in, keep the engine identical across projects, and add project code only in the
marked section.
Files (assets/)
| File | Copy to | Role |
api.ts | src/lib/api.ts | The engine (interceptors, retry, refresh, dedup, getErrorMessage) + a marked PROJECT API NAMESPACES section where per-router namespaces go |
authRefresh.ts | src/lib/authRefresh.ts | Pure decision function: refresh only on 401 from protected endpoints — a 401 from /auth/* is a credential failure and must surface its real message |
requestLogger.ts | src/lib/requestLogger.ts | Rolling request log used by the response interceptor (debug tooling) |
config.ts | src/config.ts | Runtime config: window.ENV_CONFIG (injected by docker-entrypoint.sh at container start — see deploy-cloudrun skill) with import.meta.env fallback for dev |
Invariants — why the engine looks the way it does
X-Request-IDon every request pairs with the backend'sfastapi-reqlogpackage: the same id appears in every backend log line, making cross-tier debugging one grep.- 401 handling is split:
shouldAttemptRefresh()refreshes+retries once for protected resources; auth endpoints propagate untouched (otherwise "wrong password" shows as a session error). On refresh failure with 401: clear tokens, redirect to/login. - Network errors never log the user out — they retry up to 3 times with exponential backoff (1s/2s/4s), then reject.
getErrorMessage()understands the backend's unified{code, message}envelope (fastapi-reqlog) viadata.message/data.detail, with per-status fallbacks. All Zustand stores format errors through it.- Tokens live in localStorage as
access_token/refresh_token; the backend contract isPOST /api/v1.0/auth/token/refreshwith{refresh_token}.
Wiring a project
- Copy the four files;
npm install axiosif missing. - Fill the
PROJECT API NAMESPACESsection — one exported namespace per backend router, typed functions per endpoint. Wrap idempotent GETs indeduplicate()when parallel components may fire them together. - Extend
config.tswith the project'sVITE_*keys — keep the same keys listed in docker-entrypoint.sh (deploy-cloudrun skill) or runtime config will silently be empty. - If the backend lacks the refresh endpoint or
{code, message}envelope, wire the shared backend packages first (fastapi-reqlog + the auth vertical) rather than degrading this client.
When you improve the engine here, offer to propagate the change to the sibling projects.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

