Next.js Discord

Discord Forum

how to reretrieve parameter 3

Unanswered
Yellowstripe scad posted this in #help-forum
Open in Discord
Yellowstripe scadOP
How to retrieve a http://localhost:3000/api/product/3 parameter on the way api"I need to make a request what is the method I can’t find it in the documentation

3 Replies

You would have to create a dynamic route, from there you can access the query from the request and extract the id, heres an example.
pages/api/product/[id].js
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest, response: NextResponse) {
    const { id } = request.query;

    return new Response(`Product ID is ${id}`, {
        status: 200 
    });
}
@Yellowstripe scad If you dont need any more help, please mark a solution.
Yellowstripe scadOP
Thanks for the anwser I succeeded on my own, I delete the topic