Next.js Discord

Discord Forum

Typescript API router is weird

Answered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
First approach
export default async function handler(
  req: request,
  res: response,
) {}


Second approach
export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse,
) {}


Third approach
export default async function handler(
  req: NextRequest,
  res: NextResponse,
) {}

Fourth approach
export default async function POST / GET / etc...(
...
) {}

I've seen people use bunch of diffrent syntax don't know what is old what is new what should i use.... Could somebody explain which approach is best for latest next.js app router. The 4th with combination of 3rd one i am guessing but could somebody clear this up for me
Answered by B33fb0n3
next supports the native request and response objects (that you mentioned) and they are extended as NextRequest and NextResponse to provide convenient helper for advance use cases
View full answer

6 Replies