hieudoanm/hieudoanm.github.io/axios
Claude Code and agent skill by hieudoanm/hieudoanm.github.io
- community
Checking that the SKILL.md file is still in the repository.
Best practices for HTTP requests with Axios — the promise-based HTTP client conventions for JS/TS apps. Use when writing, structuring, or reviewing Axios — covers instances, interceptors, error handling, typing, and testing.
Install
npx vskill@latest install hieudoanm/hieudoanm.github.io/axiosSKILL.md
The same SKILL.md was published earlier as hieudoanm/hieudoanm.github.io/axios.
Axios Best Practices
Axios is the promise-based HTTP client for browser + Node — axios.create(instance) with interceptors, typed from TS generics. Practical Axios leans on a single stamped `instance` per API (baseURL, timeout), interceptors for auth/error shaping only (not business logic), typed generic contracts, and defensive response validation — the client is a boundary; interceptors cross it once.
1. Instances
- One configured instance per backend/API contract:
- `baseURL`, `timeout`, credentials deliberate; never hardcode URLs in calls.
- Environment-specific config via env vars, validated at boot.
2. Interceptors
- Request interceptor: attach auth from a store/session; response: normalize errors:
- Interceptors for cross-cutting only — no logic that belongs in handlers.
- Auth-refresh flows in the response interceptor (single-flight pattern) — throttled, not naive.
3. Requests & Typing
- Typed generics per call; validate the shape you trust:
- `{ data }` destructuring standard; `params`/`data`/`method` explicit.
- No implicit `any` from `.get()` — the payload shape is the contract (validate at the seam).
4. Error Handling
- Catch and translate at the boundary — typed failures for callers:
- `axios.isAxiosError` narrows; distinguish network vs HTTP errors (`err.code`/`err.request`/`err.response`).
- Never swallow — convert errors into the domain shape for the UI layer.
5. Abort & Cancellation
- `AbortController` signal for requests tied to component lifecycles (no setState-after-unmount):
- The signal passed in request; on unmount abort.
- Cancellation errors caught (not treated as failures).
6. Testing
- Mock via `axios-mock-adapter` or intercept the adapter; assert instance-level behavior:
- Test interceptors in isolation (401 path, token attach); response-validation unit tests.
- `vi.mock("axios")` for full-mock when adapter too heavy — keep seams typed.
General Rules of Thumb
- One configured instance per API; env-driven baseURL.
- Interceptors = cross-cutting seam (auth/errors) only.
- Typed calls + shape validation at the boundary.
- Translate errors to domain types; `isAxiosError` narrows.
- Abort with lifecycle; mocks via adapter; interceptor tests.
Quick-Start Checklist
- [ ]
axios.createinstance (baseURL/timeout/headers); env-driven - [ ] Request/response interceptors for auth + error shape only
- [ ] Typed generics per call; response validated (
isAxiosError, shape guards) - [ ] Errors translated to domain errors (NotFound/Network) at the seam
- [ ]
AbortControllertied to component lifecycle - [ ] Mock adapter tests; interceptor + validation unit tests
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.skills/programming/languages/typescript/frontend/query/axios/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hieudoanm/hieudoanm.github.io/axios)