Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read request body and query params in next 13's API with app router in route.ts file?

Did not found any solution here: https://nextjs.org/docs/app/api-reference/file-conventions/route.

like image 718
Vikram Ray Avatar asked Jan 30 '26 18:01

Vikram Ray


1 Answers

For anyone looking to grab the dynamic route parameter like I was, it's in the second argument.

/api/something/[id]/route.ts

export async function GET(req, { params }) {
  const id = params.id;
}

See the docs here:
https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional

like image 190
Joe Roddy Avatar answered Feb 02 '26 22:02

Joe Roddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!