02 / 10

List methods supported by route handlers in next js?

Difficulty: 4/10
Route Handlers, HTTP Methods, App Router

The following HTTP methods are supported:

  1. 1

    GET

  2. 2

    POST

  3. 3

    PUT

  4. 4

    PATCH

  5. 5

    DELETE

  6. 6

    HEAD

  7. 7

    OPTIONS.

  8. 8

    If an unsupported method is called, Next.js will return a 405 Method Not Allowed

Scenario Questions

0-2 years experience

  1. 1You need an API endpoint that only accepts POST to submit a contact form. How would you implement that with a Next.js route handler, and what happens if a GET request reaches the same path?
  2. 2If you create a route handler file but only export a GET function, what response will a DELETE request receive?
  3. 3Explain what occurs when a browser sends an OPTIONS preflight request to a Next.js route that doesn't export an OPTIONS handler.

2-5 years experience

  1. 1A feature requires the same endpoint to serve GET for reading data and POST for creating it. Walk me through how you'd structure the route handler and any trade‑offs you consider.
  2. 2After a recent deployment, GET requests to an endpoint that previously worked now return 405. What could have gone wrong in the route‑handler implementation?
  3. 3You must support PATCH for partial updates and also enforce authentication. How would you organize the code inside the route handler to keep it clear and secure?

5-8 years experience

  1. 1Design a set of route handlers for a CRUD microservice that includes rate limiting and consistent error handling. How would you arrange files, middleware, and method exports for maintainability?
  2. 2Discuss the performance and code‑organization implications of handling many HTTP methods in a single route file versus splitting each method into its own file in a large Next.js codebase.
  3. 3If you needed to support less common verbs like CONNECT or TRACE, what changes would you make to the route handler and what security considerations would you keep in mind?

8+ years experience

  1. 1Our team is migrating legacy `pages/api` routes to the new App Router route handlers. Propose a migration plan that preserves existing method behavior while minimizing downtime.
  2. 2In a monorepo with dozens of teams, how would you enforce a consistent set of supported HTTP methods and naming conventions across all route handlers?
  3. 3We need versioned APIs (v1, v2) where each version supports a different subset of methods. How would you structure the folder hierarchy and routing to keep versions isolated and avoid method collisions?

Follow-up Questions

  • What response does Next.js send when a request uses a method you didn't export?
  • How would you add custom logic for a method like CONNECT?
  • Can you explain how middleware runs before these method handlers?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.