I need assistance with extracting the parameter value from a GET endpoint:
/api/image/id
The directory structure is as follows:
src/app/api/image/[id]/route.ts
However, when attempting to access the id parameter, I am receiving a result of null
.
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id");
return NextResponse.json({ id }, { status: 200 }); // { "id": null }
I suspect that the issue may be related to the folder structure. Unfortunately, I have been unable to determine the correct folder setup for this.
Your assistance on this matter is greatly appreciated!
I have attempted renaming route.ts to [id].ts and relocating it inside the image folder without success.