Next.js Discord

Discord Forum

I need help

Answered
Black-capped Vireo posted this in #help-forum
Open in Discord
Black-capped VireoOP
I've been trying to get API endpoints working but whenever I fetch, go to localhost:3000/api/request on my browser, and every other way, I can not get it to give me 'Hello from Next.js!', did I structure it correctly? pls help
Answered by European sprat
If you want the API route to be /api/request then you need the file structure of

app/api/request/route.ts
View full answer

6 Replies

Black-capped VireoOP
for reference, for some reason I get page not found when I fetch on postmaster
European sprat
Route Handlers in the app directory need to be named route.ts
And if that second screenshot shows what is in your request.tsx file then that's wrong too. What you have there is for pages router API routes.

Read the app directory docs on route handlers to see how to write those
European sprat
If you want the API route to be /api/request then you need the file structure of

app/api/request/route.ts
Answer
Black-capped VireoOP
Thank you