[SOLVED] Use Next.js to write API or use another framework? which one is better?

Issue

I have seen many programmers write their APIs with PHP or ASP.NET or … and request those APIs from Next.js.
We know that Next.js can implement API.
Is there a reason why most programmers do not write their APIs with Next.js?
Maybe the reason is better performance or Next.js API is not suitable for large projects or …?

And in some programs, we write our API with Next.js and from components request to them (getServerSideProps), and from those API, for example, we connect to the database and get data.
My question is why should we write API at all and why not connect directly to the database from the getServerSideProps function and receive the required data? which one is better?

Solution

Actually use case are different Next.js is similar to react but you can have SSR with it for your api you can use next.js api route i mean you can connect to your database and fetch data through next.js api but if you want to use next.js as backend or api it is not the use case you can try node for api.
and also getServerSideProps is a function to make a page SSR not for api or something else.

Answered By – Paiman Rasoli

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *