Next.js Discord

Discord Forum

Why doesn't my api route work ?Is my folder structure correct ?

Answered
i_lost_to_loba_kreygasm posted this in #help-forum
Open in Discord
Someone please help me
Answered by chisto
Try just /api
View full answer

10 Replies

If you are using app router, the file should be route.js, and you don't need pages folder

https://nextjs.org/docs/app/building-your-application/routing/route-handlers
And I think api folder has to be inside app folder too
can you tell me the endpoint for calling ?
@chisto And I think api folder has to be inside app folder too
http://localhost:3000/api/route like this ?
not working on postman
Try just /api
Answer
can I not use pages folder alongside app folder ?
Asian black bear
Yes you can, but it's not really useful.
Using that pages router API route the path would be /api/hello in your browser.
Great golden digger wasp
bro move the api folder inside of the app folder