What problem does it solve?
This Skill helps you design and implement Next.js API endpoints and Server Actions that reliably validate inputs, enforce auth, and return consistent responses instead of leaking internal errors.
Core Features & Use Cases
- Server Actions for UI mutations: Use
'use server' functions to perform authenticated write operations from React forms and components, with cache revalidation after mutations.
- API Routes for external consumers: Expose REST endpoints for webhooks, integrations, and mobile clients while keeping route handlers thin.
- Zod validation at the boundary: Parse and validate
params, query, and request bodies using Zod schemas to prevent trusting untrusted input.
- Standardized error handling: Implement
ERROR_CODES and a central handleApiError to map Zod and domain errors to correct HTTP status codes.
- Deletion safety with dependency checks: Verify related records (e.g., “hasMovements”) before deleting/soft-deleting entities to preserve business integrity.
Quick Start
Implement a new endpoint by creating an API Route under app/api/.../route.ts that uses a Zod schema to validate params/body, delegates business logic to Server Actions, and returns results via NextResponse.json with standardized errors handled by handleApiError.