Next.js Discord

Discord Forum

Differences between API routes, server actions, and edge functions

Unanswered
Taigan posted this in #help-forum
Open in Discord
TaiganOP
Hi all! I'm getting a bit confused on the differences between API routes, server actions, and edge functions (I'm using Vercel and Supabase, both of which have them). Are there any meaningful differences between when I would use each? They all seem like different implementations of edge functions, but with slightly different devex.

7 Replies

@Taigan Hi all! I'm getting a bit confused on the differences between API routes, server actions, and edge functions (I'm using Vercel and Supabase, both of which have them). Are there any meaningful differences between when I would use each? They all seem like different implementations of edge functions, but with slightly different devex.
Toyger
brief description:
api routes - backend logic with url that can be used from outside nextjs with url like https://yourdomain/api/somefunction.
server actions - nextjs only backend logic, can be used only from code inside nextjs, dont have public url(at least the one that you can easily reuse).
edge - mostly used for running some backend logic closer to client georgraphically for low latency.
TaiganOP
@Toyger Got it, I see that edge functions are more limited than standard serverless functions https://vercel.com/docs/functions/edge-functions#limitations. And I suppose that API routes are probably implemented like serverless functions under the hood?
TaiganOP
yeah makes sense. thanks man