Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to use path slugs for API routes in Next.JS?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is the official example dynamic-route-segments

you can access token as below:

export const POST = async ( req, {params} ) => {
    console.log("token value ");
    console.log(params.token);
    const postData = await req.json();
    ...
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading