Skip to content
Back to skills

Add Api Route Whatifwedigdeeper Claude Template 3

ASecurity

Create Next.js API route with validation and error handling

  • 666 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added June 2, 2026
ai-agentstypescriptbashnextjsapi

Works with

  • api

Security analysis

A100/100

Scanned June 2, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Add Api Route Whatifwedigdeeper Claude Template 3?

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

Security grade badge for Add Api Route Whatifwedigdeeper Claude Template 3
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-add-api-route-whatifwedigdeeper-claude-template-3/badge)](https://www.skillsdirectory.com/skills/majiayu000-add-api-route-whatifwedigdeeper-claude-template-3)

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
---
skill: add-api-route
description: Create Next.js API route with validation and error handling
arguments: route name and HTTP methods
---

# Add API Route: $ARGUMENTS

Create a Next.js API route with proper validation, error handling, and types.

## Process

### 1. Determine Route Structure

Parse arguments to determine:
- Route path (e.g., `users`, `posts/[id]`)
- HTTP methods (GET, POST, PUT, DELETE)
- Dynamic segments if any

### 2. Create Route File

**App Router (Next.js 13+):**
```
app/api/[route]/route.ts
```

**Pages Router:**
```
pages/api/[route].ts
```

### 3. Generate Route Handler

**App Router template:**

```typescript
import { NextRequest, NextResponse } from 'next/server';

// Types
interface RequestBody {
  // define expected body shape
}

interface ResponseData {
  // define response shape
}

// GET handler
export async function GET(request: NextRequest) {
  try {
    // Implementation
    return NextResponse.json({ data: [] });
  } catch (error) {
    console.error('GET error:', error);
    return NextResponse.json(
      { error: 'Internal server error' },
      { status: 500 }
    );
  }
}

// POST handler
export async function POST(request: NextRequest) {
  try {
    const body: RequestBody = await request.json();

    // Validate
    if (!body.requiredField) {
      return NextResponse.json(
        { error: 'Missing required field' },
        { status: 400 }
      );
    }

    // Implementation
    return NextResponse.json({ success: true }, { status: 201 });
  } catch (error) {
    console.error('POST error:', error);
    return NextResponse.json(
      { error: 'Internal server error' },
      { status: 500 }
    );
  }
}
```

### 4. Add Type Definitions

Add to `types/api.ts` or `types/index.ts`:

```typescript
export interface [Route]Request {
  // request body type
}

export interface [Route]Response {
  // response type
}
```

### 5. Create Tests

```typescript
// __tests__/api/[route].test.ts
describe('API /api/[route]', () => {
  test('GET returns data', async () => {
    const response = await fetch('/api/[route]');
    expect(response.status).toBe(200);
  });

  test('POST validates input', async () => {
    const response = await fetch('/api/[route]', {
      method: 'POST',
      body: JSON.stringify({}),
    });
    expect(response.status).toBe(400);
  });
});
```

### 6. Validate

```bash
npm run build
npm test
```

## Patterns

**Dynamic route:** `app/api/users/[id]/route.ts`

**Nested route:** `app/api/posts/[postId]/comments/route.ts`

**With middleware:** Add validation/auth in route or middleware.ts

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.