Skip to content
Back to skills

Api New

ASecurity

Create a new Next.js API route with validation, error handling, and TypeScript

  • 666 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 2, 2026
developmenttypescriptnextjsdebuggingapidatabasesecurity

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill api-new --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api New?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api New
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-api-new-claude-skill-registry/badge)](https://www.skillsdirectory.com/skills/majiayu000-api-new-claude-skill-registry)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-new
description: "Create a new Next.js API route with validation, error handling, and TypeScript"
---

# Create New API Route

Create a new Next.js API route following modern best practices for solo developers.

## Requirements

API Endpoint: $ARGUMENTS

## Implementation Guidelines

### 1. **Next.js 15 App Router** (Recommended)
Use Route Handlers in `app/api/` directory with TypeScript

### 2. **Validation**
- Use Zod for runtime type validation
- Validate input early (before DB/API calls)
- Return clear validation error messages

### 3. **Error Handling**
- Global error handling with try/catch
- Consistent error response format
- Appropriate HTTP status codes
- Never expose sensitive error details

### 4. **TypeScript**
- Strict typing for requests/responses
- Shared type definitions
- No `any` types

### 5. **Security**
- Input sanitization
- CORS configuration if needed
- Rate limiting considerations
- Authentication/authorization checks

### 6. **Response Format**
```typescript
// Success
{ data: T, success: true }

// Error
{ error: string, details?: unknown, success: false }
```

## Code Structure

Create a complete API route with:

1. **Route Handler File** - `app/api/[route]/route.ts`
2. **Validation Schema** - Zod schemas for request/response
3. **Type Definitions** - Shared TypeScript types
4. **Error Handler** - Centralized error handling
5. **Example Usage** - Client-side fetch example

## Best Practices to Follow

- Early validation before expensive operations
- Proper HTTP status codes (200, 201, 400, 401, 404, 500)
- Consistent error response format
- TypeScript strict mode
- Minimal logic in routes (use services/utils)
- Environment variable validation
- Request/response logging for debugging
- No sensitive data in responses
- No database queries without validation
- No inline business logic (extract to services)

Generate production-ready code that I can immediately use in my Next.js project.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.