Next.js Route Handlers
Route Handlers allow you to create custom request handlers for a given route using the Web Request and Response APIs. They are the App Router’s equivalent of API Routes.
Key Characteristics
- File-based: Defined in
route.tsorroute.jsfiles. - HTTP Methods: Supported methods include
GET,POST,PUT,PATCH,DELETE,HEAD, andOPTIONS. - Edge & Node.js Runtimes: Can run in either runtime, depending on configuration.
- Caching:
GETrequests are cached by default unless they use dynamic functions (likecookies()) or are explicitly opted out. - Conflict: A
route.tsfile cannot exist in the same folder as apage.tsfile.