api-route

Create secure API routes with authentication, Zod validation, and error handling.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/stancodev/obigode --skill api-route-stancodev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-route
Source: https://github.com/stancodev/obigode/tree/main/.claude/skills/api-route
Command: npx skills add https://github.com/stancodev/obigode --skill api-route-stancodev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The process of creating or modifying API routes in OBigode requires consistent authentication, robust input validation with Zod, reliable error handling, and correct TypeScript typings across all routes. This Skill provides a clear blueprint to ensure these concerns are addressed uniformly.

Core Features & Use Cases

  • Enforces authentication and authorization using the project's helpers (getSession, requireRole).
  • Validates request bodies with Zod schemas defined in src/lib/validations.
  • Implements centralized error handling and predictable response structures.
  • Ensures type-safety with the Prisma client integration in src/lib/prisma.
  • Provides guidance for structuring routes under src/app/api to maintain isolation and consistency.

Quick Start

Create a new API route under src/app/api following the example pattern and implement authentication, validation, and error handling as demonstrated.

Frequently Asked Questions about api-route

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I secure API routes with authentication and Zod validation?

Secure API routes by enforcing authentication with project helpers like getSession and requireRole, validating request bodies using Zod schemas, and returning structured error responses for predictable client interactions.

What is the best way to handle errors in API routes using Prisma and TypeScript?

Handle API route errors by implementing centralized error handling with structured response formats, ensuring Prisma client type-safety and consistent TypeScript typings across all route handlers under src/app/api.

How do I validate API request bodies with Zod schemas in a TypeScript project?

Validate API request bodies by defining Zod schemas in dedicated validation directories, then applying them within route handlers to parse and enforce input types before processing Prisma database operations.

Does this API route pattern support role-based authorization with TypeScript?

Yes, this API route pattern supports role-based authorization by utilizing the requireRole helper function, ensuring authenticated users possess specific permissions before accessing protected route endpoints.

How do I structure API routes under src/app/api to maintain consistency?

Structure API routes under src/app/api by following isolated patterns that enforce authentication, Zod input validation, Prisma type-safety, and centralized error handling uniformly across all endpoints.