Dmytro Morar
Next.js

Actions vs API Routes

Server Actions are direct server calls from React. API Routes are HTTP endpoints for external clients.

Server Actions

  • Run on the server without HTTP.
  • Called via forms or direct imports.
  • For internal mutations and UI workflows.
  • Not publicly accessible; no client bundle JS.
  • Full access to DB, cookies, and secrets.

API Routes (Route Handlers)

  • HTTP endpoints callable by any client.
  • Use for external APIs, integrations, webhooks, mobile.
  • Full HTTP surface: status, headers, CORS, streaming.
export function POST(request) {
  return Response.json({ ok: true });
}

Key differences

  • Protocol: React vs HTTP.
  • Access: internal UI vs public/external.
  • Overhead: no fetch vs network request.
  • Purpose: mutations vs integrations.

On this page