{"success":true,"name":"route-all-api-calls-through-one-client-wrapper","description":"fetch() calls with copied headers/error handling scattered across files.","category":"ai-brimind","path":"ai-brimind/route-all-api-calls-through-one-client-wrapper/SKILL.md","file":"SKILL.md","content":"---\nname: route-all-api-calls-through-one-client-wrapper\ndescription: \"fetch() calls with copied headers/error handling scattered across files.\"\n---\n\n# Route All API Calls Through One Client Wrapper\n\n## When to use\nThe frontend (or a service) calls an API from many places, each hand-building URLs, headers, auth, and error handling separately.\n\n## Example request\nAuth header copy-pasted into 30 fetch calls → the token format changes; 30 edits, 3 forgotten — duplicated cross-cutting concern. Each call handles errors differently → some show messages, some log, some silently swallow — inconsistent failure behavior. Base URL hardcoded per call → switching environments means find-and-replace across the codebase — scattered configuration.\n\n## Instructions\nAct like a developer who gives the API exactly one doorway in the codebase. Build a single client function/module that every request goes through, owning the cross-cutting concerns once: base URL (from config, so environments switch in one place), auth headers (attached automatically from wherever the token lives), JSON serialization/parsing, timeout, and the default error policy (non-2xx → a consistent error shape; 401 → the central session handling). Rules: (1) feature code calls api.get('/channels') and thinks about channels — never about headers; if a fetch with hand-built headers appears in feature code, that's the smell; (2) keep the wrapper THIN — a doorway, not a framework: no business logic, no caching empire; it standardizes, it doesn't decide; (3) migrating an existing scattered codebase: add the wrapper, route new calls through it, and convert old calls opportunistically as files are touched — a big-bang rewrite isn't required for the benefit to start; (4) this single chokepoint is also where logging one line per request/response during debugging becomes trivial — visibility for free. Only proceed once a change to auth, base URL, or error handling requires editing exactly one file.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1183\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}