Why does my API route returns 404?
Unanswered
West African Lion posted this in #help-forum
West African LionOP
I follow the basic API tutorial on Nextjs 14 doc and have double checked it here and there for the last a couple days. No luck! Please see screenshot and content of code:
import type { NextApiRequest, NextApiResponse } from 'next'
type ResponseData = {
message: string
}
export default async function GET(
req: NextApiRequest,
res: NextApiResponse<ResponseData>
) {
console.log("heyyyyyyy")
res.status(200).json({ message: 'Hello from Next.js!' })
}4 Replies
@West African Lion I follow the basic API tutorial on Nextjs 14 doc and have double checked it here and there for the last a couple days. No luck! Please see screenshot and content of code:
import type { NextApiRequest, NextApiResponse } from 'next'
type ResponseData = {
message: string
}
export default async function GET(
req: NextApiRequest,
res: NextApiResponse<ResponseData>
) {
console.log("heyyyyyyy")
res.status(200).json({ message: 'Hello from Next.js!' })
}
change the filename from
dataresource.ts to route.ts. Then it should work fine. It's described here: (see attached)@B33fb0n3 change the filename from dataresource.ts to route.ts. Then it should work fine. It's described here: (see attached)
West African LionOP
It returns a 405. I changed dataresource.ts to route.ts, moved route.ts to /app/api/
I tried diff variations of this function:
Still not working. I'll take a look again.
I tried diff variations of this function:
export default async function handler()
export default function handler()
export default async function GET()
... Still not working. I'll take a look again.
@West African Lion solved?