| name | create-handler |
| description | Create a new API handler following the handler pattern. Use when the user asks to create an endpoint, handler, or route. |
Skill: Create API Handler
Step-by-step workflow for creating a new API handler following the {{CONFIG.patterns.handlerFlowSteps}}-step handler pattern.
Scripts (Cursor skills scripts/ support)
This skill includes a scripts/ folder. The agent can run these scripts as part of the workflow:
- scripts/scaffold-handler-dirs.sh — Creates the handler directory structure. Usage:
./scripts/scaffold-handler-dirs.sh <entity> <operation> (e.g. order create).
Trigger
When the user asks to create a new API endpoint, handler, or route.
Prerequisites
- Project configuration loaded (
{{CONFIG.paths.handlerBasePath}} exists)
- Understanding of the entity and operation
Steps
Step 1: Gather Requirements
Step 2: Create Directory Structure
mkdir -p {{CONFIG.paths.handlerBasePath}}/{entity}/{operation}/logic
mkdir -p {{CONFIG.paths.handlerBasePath}}/{entity}/{operation}/schemas
Expected structure:
{{CONFIG.paths.handlerBasePath}}/{entity}/{operation}/
├── {{CONFIG.fileNames.handlerEntry}}
├── logic/
│ ├── validate-request.ts
│ ├── validate-business.ts
│ ├── pre-processing.ts
│ ├── operation.ts
│ ├── post-operation.ts
│ └── response.ts
└── schemas/
├── {{CONFIG.fileNames.requestSchema}}
└── {{CONFIG.fileNames.responseSchema}}
Step 3: Create Request Schema
Step 4: Create Response Schema
Step 5: Implement Logic Steps
For each file in logic/:
Step 6: Create Handler Entry Point
Step 7: Register Route
Step 8: Add Tests
Step 9: Validate
Completion
Handler is created, tested, and type-checked. Ready for code review.
If a step fails
- Step 2 (directory): Ensure
{{CONFIG.paths.handlerBasePath}} exists. Run mkdir -p from project root.
- Step 3–4 (schemas): If schema validation fails, check JSON Schema syntax. Use a minimal schema first.
- Step 5 (logic): If imports fail, verify paths match
{{CONFIG.paths.commonPath}} and handler structure.
- Step 8 (tests): If tests fail, run
{{CONFIG.testing.typeCheckCommand}} first. Fix type errors before test logic.
- Step 9 (validate): If type-check fails, fix reported errors before proceeding. Do not skip validation.