Did not found any solution here: https://nextjs.org/docs/app/api-reference/file-conventions/route
import { NextResponse } from ‘next/server’
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const queryParam = searchParams.get(‘param’) || ‘default’;
return NextResponse.json({ message: ‘Query param value is ${queryParam}’ })
}
have created an API route in Next.js 13 using the new app router. The route handles both GET and POST requests, demonstrating how to read query parameters and request bodies. This approach allows you to build robust and flexible API endpoints in your Next.js application
Pooja Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.