Next.js Discord

Discord Forum

Any good practice for fetching server-side ?

Answered
Vespid wasp posted this in #help-forum
Open in Discord
Vespid waspOP
I'm currently building an app where NextJS just fetches data on the server from an external API built in NestJS, is there any file structure good practices that are interesting to learn ? I would like to not put every fetch directly in server components if possible.

4 Replies

Crème D’Argent
Hey ! 👋
Maybe the best solution is to create API services file by feature. If you want to be sure that these calls are made server side only, a good thing could be to put « server-only » directive on the top of the files with server-only package.
Sedge Wren
Just to add to @Crème D’Argent , here is what you can refer https://nextjs.org/blog/security-nextjs-server-components-actions#data-access-layer
Crème D’Argent
Answer