how do you get the query string in next app dir api routes?
like on
GET example.com/api/foo?bar=%22baz%22
i want to get { bar: "baz" }
4 Replies
Maybe try
const params = new URLSearchParams(request.url.search);
Not sure if that behaves differently depending on the runtime
wait im dumb sorry
in this example they seem to also show the query string for route handler
https://beta.nextjs.org/docs/routing/route-handlers#dynamic-route-handlers
Routing: Route Handlers | Next.js
Route Handlers are a new way to create custom request handlers for a given route. All HTTP methods are supported, including GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
Client Component Hooks: useSearchParams | Next.js
API reference for the useSearchParams hook.