api-routes

pluginagentmarketplace's avatarfrom pluginagentmarketplace

Next.js API Routes - Route handlers, middleware, edge runtime

⭐1stars🔀0forks📁View on GitHub🕐Updated Dec 31, 2025

When & Why to Use This Skill

This Claude skill empowers developers to efficiently build and manage Next.js API Routes, Route Handlers, and Middleware. It streamlines the creation of server-side logic, enabling seamless integration of RESTful endpoints, edge runtime processing, and request/response handling within the Next.js ecosystem to enhance backend performance and scalability.

Use Cases

  • Developing RESTful API endpoints (GET, POST, PUT, DELETE) to handle CRUD operations and database interactions for web applications.
  • Implementing global middleware for authentication, session validation, and request redirection to secure application routes.
  • Creating dynamic route handlers using [param] patterns to fetch and serve data based on specific URL parameters.
  • Leveraging the Edge Runtime for high-performance, low-latency processing of requests at the network edge.
nameapi-routes
description"Next.js API Routes - Route handlers, middleware, edge runtime"
sasmp_version"1.3.0"
bonded_agentnextjs-expert
bond_typePRIMARY_BOND

Api Routes Skill

Overview

Build API endpoints with Next.js Route Handlers and middleware.

Capabilities

  • Route Handlers: app/api/route.ts files
  • HTTP Methods: GET, POST, PUT, DELETE, PATCH
  • Request/Response: Web API standard
  • Middleware: Edge runtime processing
  • Dynamic Routes: [param] patterns

Examples

// app/api/users/route.ts
import { NextResponse } from 'next/server'

export async function GET() {
  const users = await db.users.findMany()
  return NextResponse.json(users)
}

export async function POST(request: Request) {
  const body = await request.json()
  const user = await db.users.create(body)
  return NextResponse.json(user, { status: 201 })
}

// app/api/users/[id]/route.ts
export async function GET(
  request: Request,
  { params }: { params: { id: string } }
) {
  const user = await db.users.findById(params.id)
  return NextResponse.json(user)
}

Middleware Example

// middleware.ts
export function middleware(request: NextRequest) {
  const token = request.cookies.get('token')
  if (!token) {
    return NextResponse.redirect(new URL('/login', request.url))
  }
}