Skip to content

QuizNot attempted

Server Action or Route Handler?

A mobile app needs to create orders through your Next.js backend. What should you build?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • A Route Handler (app/api/orders/route.ts)
  • An external client like a mobile app needs a real HTTP endpoint with a stable URL, methods, status codes and headers, which is what a Route Handler (app/api/orders/route.ts) is.
  • Not a Server Action: its endpoint id is generated per build and meant to be called by your own React UI.
  • Not a Server Component: it renders UI, it can't accept a POST.
  • Not a Client Component with fetch: that is a caller, it still needs an endpoint to call.