plugins/aai-stack-nextjs/skills/nextjs-api-routes/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-stack-nextjs/skills/nextjs-api-routes/SKILL.md -a claude-code --skill nextjs-api-routesInstallation paths:
.claude/skills/nextjs-api-routes/# Next.js API Routes Skill
Patterns for building API routes in Next.js App Router.
## Route Handlers
### Basic Route Handler
```tsx
// app/api/users/route.ts
import { NextRequest, NextResponse } from 'next/server'
export async function GET(request: NextRequest) {
const users = await db.user.findMany()
return NextResponse.json(users)
}
export async function POST(request: NextRequest) {
const body = await request.json()
const user = await db.user.create({ data: body })
return NextResponse.json(user, { status: 201 })
}
```
### Dynamic Routes
```tsx
// app/api/users/[id]/route.ts
import { NextRequest, NextResponse } from 'next/server'
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
) {
const user = await db.user.findUnique({
where: { id: params.id },
})
if (!user) {
return NextResponse.json(
{ error: 'User not found' },
{ status: 404 }
)
}
return NextResponse.json(user)
}
export async function PUT(
request: NextRequest,
{ params }: { params: { id: string } }
) {
const body = await request.json()
const user = await db.user.update({
where: { id: params.id },
data: body,
})
return NextResponse.json(user)
}
export async function DELETE(
request: NextRequest,
{ params }: { params: { id: string } }
) {
await db.user.delete({ where: { id: params.id } })
return new NextResponse(null, { status: 204 })
}
```
## Request Handling
### Query Parameters
```tsx
export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const page = parseInt(searchParams.get('page') || '1')
const limit = parseInt(searchParams.get('limit') || '10')
const search = searchParams.get('search') || ''
const users = await db.user.findMany({
where: {
name: { contains: search, mode: 'insensitive' },
},
skip: (page - 1) * limit,
take: limit,
})
const total = await db.user.count({
where: {
name: {