Next.js Discord

Discord Forum

Getting the generic pathname in NextApiRequest

Unanswered
Nile tilapia posted this in #help-forum
Open in Discord
Nile tilapiaOP
Hi !
I'm looking for a way to get the generic pathname (for example /api/posts/[postId]) in my API routes. It seems that it's not available as a property of NextApiRequest, am I mistaken?

Is there any property in that request that I could use to reconstruct it?

const handler = (req: NextApiRequest) => {
  console.log(req.url); // api/posts/123, but I would like to get the string api/posts/[postId] 
}

0 Replies