Answer the question
In order to leave comments, you need to log in
What are the use cases for api-routes in Next.js?
There is such a thing https://nextjs.org/docs/api-routes/introduction As far as I understand, this api can be used effectively, because that's what it was made for. And as far as I understand, it can be used inside the application, that is, not necessarily as a source for third-party applications. But I can’t understand how to use it, and why if we can make a simple query to the database? Maybe I'm wrong, but it seems to be used together with SWR, maybe someone knows, I would be grateful for an explanation.
Answer the question
In order to leave comments, you need to log in
as I understand it, this was done in order not to raise any other express on the server in parallel with next.js (especially if this express is needed only to respond to api)
https://www.youtube.com /watch?v=61TngxLrP_0&t=1684s
here uncle talks more about it with pictures, see how one step "accessing api" is skipped, because it is now the responsibility of NEXT himself,
but when I last looked at the documentation, there was no way * store an instance of an open connection to the database, that is, you have to somehow stupidly open a connection every time you access api-route, which discouraged me from going deeper - it’s easier and better to raise express for this, and distribute the app from it to next, still
* UPD seems to still have options
https://stackoverflow.com/questions/61492595/next-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question