RECIPE
Recipe: Next.js API route writer
Generate type-safe API routes from a single Zod schema. Meridian scaffolds the handler, validation, and error envelope so you ship endpoints in seconds.
Ingredients
- Zod schema defining request body shape
- Route path and HTTP method
- Handler function signature
- Error envelope template
Steps
- Define the schema
Create a Zod object with your expected fields and constraints.
- Run the scaffold command
Meridian reads the schema and emits the route file with validation middleware.
- Wire the handler
Fill in your business logic inside the typed handler body.
- Deploy
Push to Vercel — the route is production-ready with error boundaries.
Output shape
Every generated route returns a consistent envelope: { success, data, error }. Validation failures surface as 400 responses with field-level messages. Unhandled errors return 500 with a sanitized message.