Route Handlers

Thie special file route.js designates a route segment as an API end-point.

The supported HTTP methods are: GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
Name the exported function in route.js with HTTP method names to support them. For example, to support a GET request, name the exported function GET(){...}.
As such, you can export multiple route handlers in a single route.js file by defining functions named after the different HTTP methods, eg. GET(){...}, POST(){...} etc.
If an unsupported method is called, Next.js will return a 405 Method Not Allowed response.

Next.js extends native Request and Response with NextRequest and NextResponse to provide convenient helpers for advanced use cases.

You can use a Route Handler to receive webhooks from third-party services.
For instance, if you use Stripe to receive payments, you can define a route handler /app/stripe/route.js to process confirmed payments, and specify [domain]/stripe as the webhook URL at the Stripe dashboard.

As in Next.js webpages (page.js), route handlers (route.js) support Dynamic Route Segments and Segment Config Options.