NextPlayground

Route Handlers (route.ts)

A route.ts file lets you build API endpoints inside the App Router using the standard Web Request/Response APIs. You export async functions named after HTTP verbs — GET, POST, PUT, and so on — and Next maps them to the folder’s URL. Here, /api/dice exposes a GET that reads a ?sides= query param and a POST that reads a JSON body to roll several dice at once. The widget below calls both with fetch.

nextjs.org/docs/app/building-your-application/routing/route-handlers

Dice roller

d6

Sides

Dice to roll (POST): 2

Route Handlers Demo