Add an API Endpoint
Workflow for building a new API route end-to-end
CLAUDE.md
When adding a new API endpoint:
- Define the route path, HTTP method, request shape, and response shape.
- Add input validation using a schema validator (Zod, Joi, etc.).
- Create or update the service function that handles the business logic.
- Wire the route handler: parse input, call the service, format the response.
- Add error handling: return appropriate status codes for validation errors (400), not found (404), and server errors (500).
- Write integration tests covering the happy path, validation failures, and edge cases.
- Document the endpoint with request/response examples.
- Run the test suite and manually test with a sample request.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.