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?
nodemon
then this wouldn't work out of the box withNext.js
and would need some configuration. However, choosing to opt out ofNext.js
' API and replace it with another server would make you lose out on a lot that Vercel has to offer