Knowledge Maxxing
← Back to topic library
Dev MaxxingIntermediateNext.js75 sec

Route Handler

A Route Handler is a Next.js file that responds to HTTP requests directly, letting a project expose its own API endpoints alongside its pages.

Prerequisite: Next.js route

What matters

This lets a single Next.js project serve both its user-facing pages and its backend API from the same codebase, without needing an entirely separate backend server.

Example

A file at 'app/api/posts/route.ts' can define a Route Handler that responds to GET and POST requests at the '/api/posts' endpoint.

Common misconception

A Route Handler is not the same as a page; a page renders UI for a browser, while a Route Handler returns raw data or another kind of response.

Recall question

What does a Route Handler let a Next.js project do that a page alone cannot?

Keywords and related concepts

Route HandlerNext.jsAPI routesnext.js route

Related topics

Next.js route
Dev MaxxingIntermediate
API endpoint
Dev MaxxingBeginner