route-handlers

Solid

This skill should be used when the user asks to "create an API route", "add an endpoint", "build a REST API", "handle POST requests", "create route handlers", "stream responses", or needs guidance on Next.js API development in the App Router.

API & Backend 3,047 stars 377 forks Updated today MIT

Install

View on GitHub

Quality Score: 96/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Next.js Route Handlers ## Overview Route Handlers allow you to create API endpoints using the Web Request and Response APIs. They're defined in `route.ts` files within the `app` directory. ## Basic Structure ### File Convention Route handlers use `route.ts` (or `route.js`): ``` app/ ├── api/ │ ├── users/ │ │ └── route.ts # /api/users │ └── posts/ │ ├── route.ts # /api/posts │ └── [id]/ │ └── route.ts # /api/posts/:id ``` ### HTTP Methods Export functions named after HTTP methods: ```tsx // app/api/users/route.ts import { NextResponse } from 'next/server' export async function GET() { const users = await db.user.findMany() return NextResponse.json(users) } export async function POST(request: Request) { const body = await request.json() const user = await db.user.create({ data: body }) return NextResponse.json(user, { status: 201 }) } ``` Supported methods: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` ## Request Handling ### Reading Request Body ```tsx export async function POST(request: Request) { // JSON body const json = await request.json() // Form data const formData = await request.formData() const name = formData.get('name') // Text body const text = await request.text() return NextResponse.json({ received: true }) } ``` ### URL Parameters Dynamic route parameters: ```tsx // app/api/posts/[id]/route.ts interface RouteContext { params: Promise<{ id: string }> } expor...

Details

Author
davepoon
Repository
davepoon/buildwithclaude
Created
10 months ago
Last Updated
today
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category