Next.js Discord

Discord Forum

Rest api with nextjs13 doesn't work

Unanswered
Golden-cheeked Warbler posted this in #help-forum
Open in Discord
Golden-cheeked WarblerOP
I keep getting this error message when calling the api.
Am I implementing it the correct way?
import { NextRequest, NextResponse } from "next/server";
export async function GET(req: NextRequest, res: NextResponse) {
  return NextResponse.json({
    message: "Hello from the API",
  });
}

1 Reply

You have to name the file “route.ts” rather than page