Next.js Discord

Discord Forum

server action instead of api route ?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have been using api routes to get or post data to my vercel postgres db. Can I or should i use a server action function instead to get or post (it would simplify my code if i only had a single function to call w a "use server" to get to my db. Also would you organize all your server action functions in a folder called 'actions" ?

3 Replies

Nile Crocodile
yep that's totally fine
those server actions get transformed into RPC calls in client components
and gives you type suggestions without declaring each type on each rest call