Next.js Discord

Discord Forum

Is there a tutorial for nextjs with HTTP APIs instead of server actions?

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
I'm upgrading from nextjs 12 and i really prefer the old flow. But i would like to refresh my memory with all the latest features while using the HTTP API request method. Is there any guide for this?

6 Replies

Giant panda
This isn't specific to Next. Using conventional REST API calls for mutations is as easy as using native fetch or useMutation from react-query which is recommended for serious projects.
@Giant panda This isn't specific to Next. Using conventional REST API calls for mutations is as easy as using native `fetch` or `useMutation` from `react-query` which is recommended for serious projects.
Brown bearOP
REST API is recommended for serious projects?

Do you simply create an api folder inside the app folder like it used to be with an api folder inside the pages folder?
Giant panda
If you do not want to use server actions for mutations then yes, you can just create REST endpoints (with a similar, but slightly different syntax) and consume them like before.
@Giant panda If you do not want to use server actions for mutations then yes, you can just create REST endpoints (with a similar, but slightly different syntax) and consume them like before.
Brown bearOP
Great, thank you!

Can you point me in the right direction to read about REST endpoints & syntax for nextjs 14?
@Giant panda If you do not want to use server actions for mutations then yes, you can just create REST endpoints (with a similar, but slightly different syntax) and consume them like before.
bit misleading to say this without warning users of the router cache. assuming you dont force-turn off the router cache or use router.refresh() to refresh literally everything, server actions are the only way to revalidate the router cache during a mutation