Next.js Discord

Discord Forum

API showing 404 even though file is in app/api folder

Answered
Persian posted this in #help-forum
Open in Discord
PersianOP
File structure is as follows, api is supposed to spit out John Doe on localhost:3000/api/hello but instead shows 404

example code would be nice

Thank you
Answered by joulev
it needs to be app/api/hello/route.js since you are using the app directory
View full answer

6 Replies

Answer
also the syntax is drastically different
not export default function handler(req, res)
if you want to keep the old syntax and the old way of doing it, then use the pages directory and use pages/api/hello.js or pages/api/hello/index.js