React Template Data Access Endpoint
What This Skill Produces
A safe endpoint integration with aligned parsing and mocks:
src/data-access/<feature>/<feature>.schema.ts: Zod request/response contractssrc/data-access/<feature>/<feature>.api.ts: exported API function(s) that parse responsesmocks/api.mockoon.json: endpoint and response shape alignment- Feature consumers updated to import from feature-specific data-access modules
When To Use
Use this skill when asked to:
- Add a new backend endpoint to the frontend
- Refactor existing API access to typed parsing
- Fix drift between frontend contracts and Mockoon mocks
- Remove direct
httpClientusage from features
Required Inputs
Collect or infer before coding:
- HTTP method and endpoint path
- Request payload and query params
- Response contract (success and expected error formats)
- Calling features and query/mutation usage
- Mockoon behavior required for local/dev flows
Workflow
- Define or Update Schemas
- Add request/response Zod schemas and exported types in
<feature>.schema.ts. - Keep parsers internal to data-access.
- Validate nested collections/pagination contracts explicitly.
- Implement API Function
- Add exported function in
<feature>.api.tsusinghttpClient. - Parse JSON response with schema before returning.
- Keep transport concerns (paths, params, body) inside data-access.
- Update Callers
- Ensure features import API functions from
~/data-access/<feature>/<feature>.api. - Remove direct
httpClientcalls from feature files. - Keep feature handlers focused on query/mutation orchestration.
- Sync Mocks
- Update
mocks/api.mockoon.jsonfor endpoint path and response shape. - Keep paths aligned with
/apiprefix conventions. - Ensure mock payloads satisfy Zod parsers.
- Verify
- Run
pnpm type-check. - Run
pnpm buildif API changes affect route-level features. - Smoke-test key flows that depend on changed endpoints.
Decision Points
-
Schema strictness:
- Prefer strict object shapes for core entities.
- Use optional/nullish fields only when backend actually returns them.
-
Function granularity:
- Keep one API function per endpoint/action.
- Share helper builders only if duplication is substantial.
-
Error handling:
- Normalize known backend error states where the app has explicit flows.
- Let unknown errors propagate for global handling/toasts.
Completion Checklist
- Endpoint contracts exist in
<feature>.schema.ts. - API function exists in
<feature>.api.tsand returns parsed data. - No direct feature-level
httpClientcalls remain for changed flows. - Mockoon endpoint is aligned with path and contract.
pnpm type-checkpasses.pnpm buildpasses when affected UI/routes changed.