api-endpoint
Scaffold a REST API endpoint with route, controller, validation, and tests. Use when creating new API endpoints, adding resources, or when asked to build a new backend route.
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 18
- Forks
- 1
01 前言 Front Matter
- name
- api-endpoint
- metadata
- { "forged-by": "codex-agent", "last-used": "2026-02-26", "forged-from": "session-2026-02-18", "usage-count": "9", "forged-reason": "Third endpoint scaffolded with identical structure — time to encode the pattern" }
- description
- Scaffold a REST API endpoint with route, controller, validation, and tests. Use when creating new API endpoints, adding resources, or when asked to build a new backend route.
03 SKILL.md 正文
API Endpoint Scaffold
Create a new REST API endpoint following project conventions.
Inputs
- Entity name (singular, e.g.,
comment) - Fields (name:type pairs, e.g.,
body:string, author_id:number) - Auth required? (boolean, defaults to
true) - Nested under? (optional parent entity, e.g.,
post)
Steps
-
Create the route file
src/routes/{entity}.routes.ts- Define CRUD routes:
GET /,GET /:id,POST /,PUT /:id,DELETE /:id - If nested:
GET /{parent}s/:parentId/{entity}s
- Define CRUD routes:
-
Create the controller
src/controllers/{entity}.controller.ts- One method per route
- All responses use
{ data, error, meta }shape - Handle not-found with 404, validation with 422
-
Create the validation schema
src/validators/{entity}.validator.ts- Use Zod schemas matching the field definitions
- Separate schemas for create vs. update (update = partial)
-
Create the test file
tests/api/{entity}.test.ts- Test each CRUD operation
- Test validation (bad input returns 422)
- Test auth (if required: 401 without token)
- Use test factories for fixtures
-
Register the route
src/routes/index.ts- Add import +
app.use('/{entity}s', {entity}Routes) - If auth required: add auth middleware
- Add import +
Conventions
- Route paths are plural (
/comments, not/comment) - File names are singular (
comment.routes.ts) - All endpoints return
{ data, error, meta } metaincludes pagination for list endpoints- Auth middleware is applied at the route level, not controller level
Edge Cases
- File upload endpoints: Add
multermiddleware, acceptmultipart/form-data - Nested routes: Parent ID is validated in middleware (404 if parent doesn't exist)
- Soft delete:
DELETEsetsdeleted_attimestamp, doesn't remove the row
04 同仓库更多 Skills
skillforge
Create or update a reusable agent skill. Use when you notice a repeated pattern, when a workflow should be persisted for future sessions, or when asked to forge/create/scaffold a new skill.
skillforge
Create or update a reusable agent skill. Use when you notice a repeated pattern, when a workflow should be persisted for future sessions, or when asked to forge/create/scaffold a new skill.
deploy-preview
Deploy a preview branch to the staging environment for review. Use when a feature branch is ready for visual review, when someone asks to "deploy this for review", or before opening a PR.
component-scaffold
Create a new React component with co-located test, story, and styles. Use when creating new UI components, when asked to scaffold/generate a component, or when building new pages.
bug-triage
Triage a bug report into an actionable GitHub issue with severity, reproduction steps, and assignment. Use when a bug is reported, when error logs need investigation, or when asked to file/triage an issue.
finish-the-loop
Close implementation loops with target-bound independent evidence and a portable proof receipt. Use when an agent changes a real system and must earn a completion claim that survives the session.