Differences between API routes, server actions, and edge functions
Unanswered
Taigan posted this in #help-forum
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
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.
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.
@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.
edge - mostly used for running some backend logic closer to client georgraphically for low latency.How to use them? Do you have some docs for me?
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?
@Taigan <@536484914221285376> 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?
Toyger
they say it's https://vercel.com/docs/functions/edge-functions/edge-runtime some kind of limited nodejs runtime.
for api yeah more likely like some serverless that just mapped to /api route.
for api yeah more likely like some serverless that just mapped to /api route.
TaiganOP
yeah makes sense. thanks man