#How do I get req query params in a GET route handler?
1 messages · Page 1 of 1 (latest)
Hi @valid iron. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To get query parameters in a GET route handler, you can use the NextRequest object from next/server. Here's an example of how to access query parameters in a route handler:
import type { NextRequest } from 'next/server';
export const config = {
runtime: 'edge',
};
export default async function handler(req: NextRequest) {
const { searchParams } = new URL(req.url);
const email = searchParams.get('email');
return new Response(email);
}
In this example, the searchParams object is used to get the value of the email query parameter from the request URL. You can replace email with the name of the query parameter you want to access.
Source: Edge API Routes - Query Parameters (https://nextjs.org/docs/api-routes/edge-api-routes)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@valid iron kapa.ai is still learning and improving, please let us how it did by reacting below
@valid iron There is a dedicated #1089389297548931182 for that.