{"success":true,"name":"put-one-api-client-layer-in-the-frontend-no-scattered-fetch-","description":"Frontend code calls the backend with raw fetch/axios all over the codebase","category":"ai-brimind","path":"ai-brimind/put-one-api-client-layer-in-the-frontend-no-scattered-fetch-/SKILL.md","file":"SKILL.md","content":"---\nname: put-one-api-client-layer-in-the-frontend-no-scattered-fetch-\ndescription: \"Frontend code calls the backend with raw fetch/axios all over the codebase\"\n---\n\n# Put One API Client Layer in the Frontend — No Scattered fetch Calls\n\n## When to use\nYou are adding an API call in a frontend, and calls to the backend are (or would be) written inline in components with their own headers, URLs, and error handling.\n\n## Example request\nAuth header logic copy-pasted in 20 components → token refresh changes and 20 places break; one client layer owns request plumbing. — Each component parses errors differently → the same failure shows five different behaviors; centralized response/error handling is the single owner. — Base URL hardcoded per call → switching environments means find-and-replace; the client layer reads it from config once. — Endpoint response shape changes → every caller updated by hand; typed API functions make the compiler find the callers.\n\n## Instructions\nAct as a frontend boundary architect who allows exactly one doorway between the app and the backend. When adding API calls: 1) Check for the existing API client layer (a wrapper module, generated client, or data-fetching library setup) and add your call there — never inline fetch/axios in a component; if no layer exists, creating it is the first task. 2) Centralize the plumbing in that layer once: base URL from config, auth headers and refresh, the shared error envelope parsing, retries — components should call named functions like getUser(id), not assemble requests. 3) Type each function's input and output to mirror the API contract, so a contract change becomes compiler errors at call sites instead of runtime surprises. 4) Check whether the ecosystem already solves the layer (an OpenAPI-generated client, the data-fetching library the project uses) before hand-writing wrappers — reuse first. 5) If you find scattered raw calls while working, route your change through the layer and flag the strays. Only proceed once the call lives behind the single doorway, and explain how centralizing turns future API changes into one-file edits rather than a hunt.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #909\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}