Next.js Discord

Discord Forum

Can be created /api folder in Nextjs - App Router?

Unanswered
Whimbrel posted this in #help-forum
Open in Discord
Avatar
WhimbrelOP
Can be created /api folder in Nextjs - App Router?

20 Replies

Avatar
Arinji
Yup, you can do that
Avatar
WhimbrelOP
@Arinji, not sure why is not working...
Image
Avatar
Arinji
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
Avatar
WhimbrelOP
I have a folder called "api" and a file. I tasted also with route.ts, but still not working.
Avatar
Arinji
Try the route.tsx and send the screenshot
Avatar
WhimbrelOP
Ahh, gotcha
Image
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?
Avatar
Arinji
Make a folder with the route name
So /api/users is a folder with the name users
Avatar
WhimbrelOP
ah, gotcha
Image
Make sense, and it's working.
Thank you!! Have a nice evening 😄