Next.js Route Handler API
Create a typed API endpoint using app/api/*/route.ts with explicit
validation and security headers.
When to Use
- •Build API routes or BFF endpoints
- •Server-only logic and secrets
Inputs
- •Route path (e.g.
app/api/users/route.ts) - •HTTP methods
- •Request/response shapes
- •Auth requirements and rate limits
Instructions
- •Create
route.tswith the required HTTP methods. - •Validate input and return typed responses.
- •Use
NextResponsewith explicit status codes. - •Add auth and rate limiting where required.
- •Set security headers where appropriate.
- •Keep secrets server-only.
Output
- •Route Handler with validated, typed request/response and security controls.