I searched in articles and YouTube videos about how to fix error 404 when calling a API router for example /api/hello/
even when I saw the documentation in Next.js website I didn’t find any solution for this problem, and I even create a new project from scratch, but the solution is still exist.
this is the simple API router code of app/api/hello/router.ts
import { NextResponse, NextRequest } from "next/server";
export async function GET(request: NextRequest) {
return NextResponse.json({
messsage: "hello world",
});
}
I really need a help form this error
2
Answers
your api file should be
route.ts
you have
router.ts
so you actually do not have an api endpoint
rename your file to route.ts instead of router.ts