Next.js Discord

Discord Forum

Difference between Route Handlers/API Routes and Server Actions

Unanswered
Northern Shoveler posted this in #help-forum
Open in Discord
Northern ShovelerOP
Hi guys, I've a little bit of mess in my mind. Can someone briefly explain the differences between these entities in Next.JS?
- Route Handlers/API Routes
- Server Actions

5 Replies

Siberian
Server actions basically create an API endpoint under the hood, with the added benefit that you can call the function directly, you get type safety etc.

Manually defining an API endpoint gives you more control over stuff like what verb you use (PATCH, POST, ...) etc and also allow you to define what the actual route of the endpoint is, which you'd need if you wanted to call it from outside your next js application
Yes that’s correct. There are fewer times where you might need a route handler now
Siberian
FWIW I am a fan of using them when learning Next cause it makes the boundary between client/server more obvious
not knowing that leads to a lot of confusion