Part 13 / Topic 5 of 6
Route Handler or Server Action? The installed docs' own stated purpose for each
Part 12 already quoted the installed server-actions.md guide calling every Server Action "a POST request against the page that invokes it" — reachable, but always through this app's own rendered page. The installed backend-for-frontend.md guide draws the opposite boundary for a Route Handler, just as directly: "Route Handlers are public HTTP endpoints. Any client can access them." And for Server Actions specifically: "Server Actions let you run server-side code from the client. Their primary purpose is to mutate data from your frontend client."
Put together, these two sentences are the actual decision rule, not a rule of thumb invented for this course:
| Question | Answer points to |
|---|---|
| Does this app's own rendered form/button trigger the mutation? | Server Action |
Does something else entirely — another service, a webhook, a curl script, a mobile app with no React — need to call this? |
Route Handler |
Does the response need a content type other than the RSC/HTML Server Actions produce — plain JSON for a non-browser caller, a file download, a text/plain body? |
Route Handler |
Is this a GET that something might want cached, polled, or fetched from outside a React render at all? |
Route Handler (Server Actions are not cacheable GET-style reads — Part 11's whole caching model assumes a Server Component read, not an action) |
This part's own two routes split exactly along that line: GET /api/status/[pnr] exists because some other script (this course's own curl commands, in practice; a real status-check bot, in a real product) wants PNR data with no HTML and no React involved — and POST /api/status/[pnr]/delay exists because the caller is a railway ops system's backend, not this app's own UI. Neither has an equivalent <form> anywhere in this harness, because neither should.
Done here? The practice set for Part 13 — including the solutions — is on the part page.