How to get ID from /api/something/[id]
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
I want to access /api/something/[id] the id part.
export default async function GET(req: Request, res: Response) {
}Answered by B33fb0n3
you can get it via the params like:
app/items/[slug]/route.tsexport async function GET(
request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug // 'a', 'b', or 'c'
}8 Replies
RhinelanderOP
Is req.url the way?
you can get it via the params like:
app/items/[slug]/route.tsexport async function GET(
request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug // 'a', 'b', or 'c'
}Answer
So in your case
params.idRhinelanderOP
Thank you once again!
happy to help once again 🙂
RhinelanderOP
I don't want to create new post but where would you suggest me to learn next.js validation. Like the proper way to handle let say trycatch and how to display that data in toast.
@Rhinelander I don't want to create new post but where would you suggest me to learn next.js validation. Like the proper way to handle let say trycatch and how to display that data in toast.
learn
react-hook-form and zod. if you have any question please open up a new thread