Next.js › API Routes
How do you read query parameters and the request body inside an API route?
BeginnerAnswer
In the Pages Router, the request object passed to your handler function gives you access to query parameters through req.query and to the submitted data through req.body, letting you build endpoints that respond differently based on what the client sent.
export default function handler(req, res) {
const { id } = req.query;
const { name } = req.body;
res.status(200).json({ id, name });
}Real-world example A product search API route reads a search term from the query string and returns matching products, letting the frontend build a live search feature.