Next.js Discord

Discord Forum

API giving a 404 error

Answered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I am testing the API feature in next js and it keeps giving me a 404 error.
My files are in the following dir: app/pages/api/hello.js
The following url: http://localhost:3000/api/hello

here is the code in my hello.js file:
export default function handler(req, res) {
res.status(200).json({ text: 'Hello' })
}


Thanks in advance!
Answered by Ray
// app/api/hello/route.ts
export async function GET() {
  return Response.json({ hello: 'world' })
}
View full answer

5 Replies

// app/api/hello/route.ts
export async function GET() {
  return Response.json({ hello: 'world' })
}
Answer
been stuck on this for a bit
IT WORKS!