Next.js Discord

Discord Forum

i dont understand new API route structure

Answered
Gray Partridge posted this in #help-forum
Open in Discord
Gray PartridgeOP
as you can see my screenshot i created simple API and tested on Thunder Client its get 500 error
my api path is /src/app/api/test
inside /test i use page.js
before nextjs 14 this method is working fine
how can i fix this problem ?
Answered by B33fb0n3
no, you define your route as:
your/route/test/
and inside this folder structure is a route.js and inside the route.js you can add code
View full answer

17 Replies

are you using the app dir or pages dir?
@B33fb0n3 are you using the app dir or pages dir?
Gray PartridgeOP
app dir.
then your route handler must be named route.js
@B33fb0n3 then your route handler must be named route.js
Gray PartridgeOP
all api folder must be route.js instead page.js am i right ?
also the code inside the route need to be changed
you might want to take a look at this guide for route handlers: https://nextjs.org/docs/app/building-your-application/routing/route-handlers
@Gray Partridge all api folder must be route.js instead page.js am i right ?
no, you define your route as:
your/route/test/
and inside this folder structure is a route.js and inside the route.js you can add code
Answer
Gray PartridgeOP
ok this it worked !
you solved my problem
great to hear 🙂
Gray PartridgeOP
Thanks you i close this thread
wait
Gray PartridgeOP
ok