Problem Statement
How do you handle different HTTP methods in an API route (Pages Router)?
Explanation
In Pages Router API routes, you check the req.method property and use conditional statements or switch cases to handle different HTTP methods like GET, POST, PUT, DELETE within the same handler function. You typically return a 405 Method Not Allowed error for unsupported methods, and can organize code with helper functions for each method. This differs from App Router's Route Handlers where you export separate named functions for each method, making the App Router approach cleaner and more explicit for handling multiple HTTP methods.
