mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-28 03:04:48 +00:00
Replace ad-hoc fetch httpClient with api/request.ts (axios interceptors, envelope unwrap, auth refresh) and defineApi-based resource modules. Move session hydration into api/auth, sync both templates, and update docs. Co-authored-by: zuiidea <zuiiidea@gmail.com>
1.4 KiB
1.4 KiB
applyTo, description
| applyTo | description |
|---|---|
| src/api/**/*.ts,src/mocks/handlers/**/*.ts,src/mocks/createHandler.ts | Use when editing API clients, schemas, HTTP behavior, response types, or MSW endpoint handlers. Keywords: api, request, defineApi, schema, zod, handler, endpoint, auth, users. |
API Instructions
Purpose
Maintain strict API contracts and a single call path: schemas → defineApi resource modules → UI. Transport lives in src/api/request.ts (axios + interceptors).
Do
- Define APIs with
defineApiinsrc/api/<resource>.ts(methoddefaults toGET; useparams/query/body+output). - Keep Zod schemas in
src/api/schemas.tsas the single contract; parse inputs/outputs insidedefineApi. - Keep MSW handler envelopes consistent (
code,data,message) and aligned with schemas. - Co-locate React Query keys with resource modules (e.g.
userQueryKeys). - Use
hydrateSessionfrom@/api/authafter login/register or when restoring a session.
Do Not
- Do not call
axiosor@/api/requesttransport helpers from routes/components — import resource functions only (listUsers,login, …). - Do not return ad-hoc response shapes for one-off convenience.
- Do not bypass schema parsing in new client mutations/queries.
- Do not mix unrelated domain endpoints in the same module.
Validation
- Verify TypeScript and schema parsing paths compile cleanly.
- Run:
vp check --no-fmt