Next.js
/Beginner
REST API Endpoints
Definition
Exporting specific named functions (`GET`, `POST`, `PUT`, `DELETE`) from a `route.ts` file to handle different types of HTTP requests.
Explain Like I'm New
If an external app sends data to your server to CREATE a user, it sends a `POST` request. You write an `export async function POST()` to handle it. If they want to READ a user, you write a `GET` function. They can all live in the exact same `route.ts` file.
Real World Example
Creating a standard CRUD API for a mobile app. `GET /api/users` returns the list. `POST /api/users` creates a new one.
Common Use Cases
- •RESTful API architecture
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Which HTTP method is traditionally used to UPDATE existing data?
intermediate
- If a client sends a `DELETE` request to your Route Handler, but you only exported a `GET` and `POST` function, what happens?