Back

API Routes

Route handlers let you build backend endpoints inside your Next.js app. Create a route.ts file and export functions named after HTTP methods (GET, POST, etc.).

// app/api/hello/route.ts  ->  /api/hello
export async function GET() {
  return Response.json({ message: "Hello!" })
}

export async function POST(request: Request) {
  const body = await request.json()
  return Response.json({ received: body }, { status: 201 })
}

// Calling it from the frontend
const res = await fetch("/api/hello")
const data = await res.json()

Roadmap