I use app router of Next.js v.14 and have the following directories structure:
/app/api/github/webhook/[token]/route.ts
How can I get the [token]
value inside the POST
request handler? Are there dedicated fields in the NextRequest
structure?
The official documentation completely missed the point of using [slugs]
inside API routes.
Here is the official example dynamic-route-segments.
You can access the token as below:
export const POST = async ( req, {params} ) => {
console.log("token value ");
console.log(params.token);
const postData = await req.json();
...
}