# Next API Scaffold

> Creates Next.js API routes with TypeScript, error handling, and validation. Use when user says "create API route", "add endpoint", "new API", mentions /api/ paths, or wants to add a Next.js route handler.

- Skill: `tomevault-io/next-api-scaffold` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/next-api-scaffold`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/next-api-scaffold/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/next-api-scaffold

---


# Next.js API Route Scaffolder

## GET Endpoint Template

```typescript
// app/api/users/route.ts
import { NextRequest, NextResponse } from 'next/server'

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const limit = searchParams.get('limit') || '10'
    
    // TODO: Fetch from database
    const users = []
    
    return NextResponse.json({ success: true, data: users })
  } catch (error) {
    console.error('GET /api/users error:', error)
    return NextResponse.json(
      { success: false, error: 'Internal server error' },
      { status: 500 }
    )
  }
}
```

## POST Endpoint Template

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

const schema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
})

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const validation = schema.safeParse(body)
    
    if (!validation.success) {
      return NextResponse.json(
        { success: false, errors: validation.error.errors },
        { status: 400 }
      )
    }
    
    // TODO: Save to database
    return NextResponse.json({ success: true, data: validation.data }, { status: 201 })
  } catch (error) {
    return NextResponse.json({ success: false, error: 'Internal server error' }, { status: 500 })
  }
}
```

## Dynamic Route Template

```typescript
// app/api/users/[id]/route.ts
export async function GET(
  request: NextRequest,
  { params }: { params: { id: string } }
) {
  const { id } = params
  // TODO: Fetch user by id
  return NextResponse.json({ success: true, data: { id } })
}
```

---
> Source: [Tokenized2027/Claude-Initialization-V7](https://github.com/Tokenized2027/Claude-Initialization-V7) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-15 -->

