Documentation Index
Fetch the complete documentation index at: https://docs.getsabo.com/llms.txt
Use this file to discover all available pages before exploring further.
Use this guide as your blueprint for building API routes under
src/app/api/*. It covers input validation with Zod, optional authentication guards with Supabase, consistent responses, security, and testing. For a concrete, fully implemented example, see Contact Form API.To decide between protecting at the edge (middleware) vs inside the route (server guard), see Routing & Middleware. In general, use route-level guards for most APIs, and reserve middleware for global page gating or cross‑cutting concerns.
Route structure
Each endpoint lives in its own folder with aroute.ts file:
src/app/api/contact/route.ts
Validation with Zod
- Define a schema near the top of your file:
src/app/api/example/route.ts
- Parse and handle validation errors consistently:
src/app/api/contact/route.ts
The error shape above matches the Contact endpoint, keeping your API responses predictable across routes.
Handling non-JSON payloads
Some integrations (Stripe Checkout, webhooks, file uploads) submit data asapplication/x-www-form-urlencoded or multipart/form-data. Read those bodies with request.formData() before passing values into your schema:
src/app/api/checkout_sessions/route.ts
Optional: Authentication guard (Supabase)
For private endpoints, use the server client to read the session and return 401 when missing:src/app/api/private/route.ts
Consistent responses
- Success (200/201):
{ success: true, ... } - Validation error (400):
{ success: false, message: "Validation failed", errors: [...] } - Unauthorized (401/403):
{ success: false, message: "Unauthorized" } - Server error (500):
{ success: false, message: "An error occurred while processing your request" }
Security checklist
- Accept only needed methods; return 405 for others.
- Validate and sanitize all inputs (Zod).
- Do not log secrets or PII. Redact when necessary.
- Use auth guards for protected resources.
- Avoid open redirects and untrusted origins.
src/app/api/contact/route.ts
Testing locally
Use Contact Form API as a reference implementation for validation, error handling, and method handling.