tezvyn:

How do you handle multiple HTTP methods in a single route.ts file?

Source: nextjs.orgintermediate

Tests App Router Route Handler REST conventions. A strong answer exports named GET, PUT, DELETE handlers using NextRequest and NextResponse.json, plus 405 for unsupported methods.

Tests whether you understand Next.js App Router file-system routing for RESTful APIs. A good answer covers four things in order: first, named exports for each HTTP verb like GET, PUT, and DELETE in one route.ts file; second, typing the request with NextRequest and returning NextResponse.json with proper status codes; third, handling dynamic segments via params or request URL; fourth, returning a 405 for unsupported methods or omitting them.

Read the original → nextjs.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How do you handle multiple HTTP methods in a single route.ts file? · Tezvyn