React Tutorial #21: Next.js API Routes and Server Actions
In the previous tutorial, you learned Server Components. Now let’s add a backend — Route Handlers for APIs and Server Actions for mutations. Two Ways to Write Server Code Next.js gives you two tools for server-side logic: Route Handlers — traditional REST API endpoints (app/api/route.ts) Server Actions — functions that run on the server, called from the client Use Route Handlers when you need a public API (for mobile apps, third-party clients, or webhooks). Use Server Actions for form submissions and mutations within your Next.js app. ...