Next.js Discord

Discord Forum

Recommended way to fetch data from vercel postgres database

Answered
Argentine hake posted this in #help-forum
Open in Discord
Argentine hakeOP
I am using the postgres database that vercel provides, however, I am unsure on the best approach to fetching data from it. Historically it seems like it was preferred to create API routes and then create a fetch request get tge data. However, with NextJS 14 and the introduction of server actions it seems like the preferred approach is to do it all in the server component.

tldr; should I fetch data inside of server component, or should I create API routes?
Answered by Toyger
api is prefferable only if you need to use them externally, not only through your site.
server components and server actions is more preferable in all other cases.
View full answer

2 Replies

Toyger
api is prefferable only if you need to use them externally, not only through your site.
server components and server actions is more preferable in all other cases.
Answer
@Toyger api is prefferable only if you need to use them externally, not only through your site. server components and server actions is more preferable in all other cases.
Argentine hakeOP
I see, well I plan on using it for the site only so I'll be using server components and server actions. Thank you!