← Back to Docs
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

  1. Define the schema

    Create a Zod object with your expected fields and constraints.

  2. Run the scaffold command

    Meridian reads the schema and emits the route file with validation middleware.

  3. Wire the handler

    Fill in your business logic inside the typed handler body.

  4. 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.

Related

Meridian — ship endpoints, not boilerplate.