Can be created /api folder in Nextjs - App Router?
Unanswered
Whimbrel posted this in #help-forum
WhimbrelOP
Can be created /api folder in Nextjs - App Router?
20 Replies
Yup, you can do that
Most of the time, the docs help out
https://nextjs.org/docs/app/building-your-application/routing/route-handlers
https://nextjs.org/docs/app/building-your-application/routing/route-handlers
WhimbrelOP
@Arinji, not sure why is not working...
Read the docs please
You need to make a folder
Its folder routing
The file needs to be route.tsx
And the folder name will be the route name
WhimbrelOP
I have a folder called "api" and a file. I tasted also with route.ts, but still not working.
Try the route.tsx and send the screenshot
WhimbrelOP
Ahh, gotcha
So basically I need to call /api not api/route as it was before (Pages)
Hmm, that's tricky, what about if I want to have some other APIs in /api folder?
Make a folder with the route name
So /api/users is a folder with the name users
WhimbrelOP
ah, gotcha
Make sense, and it's working.
Thank you!! Have a nice evening 😄