Next.js
/Intermediate
Request & Response Objects
Definition
Next.js Route Handlers strictly use the native Web standard `Request` and `Response` objects, replacing the old Node.js/Express `req` and `res` objects.
Explain Like I'm New
When handling APIs, you need to read the incoming data (Request) and send data back (Response). Next.js uses the exact same `Request` object that Service Workers and the `fetch` API use, making the knowledge transferable.
Real World Example
Reading a `?search=shoes` URL query parameter from the incoming Request, and returning a `404 Not Found` Response if no shoes exist.
Common Use Cases
- •Reading URL parameters
- •Parsing JSON bodies
- •Setting HTTP headers
Interactive Example
Loading Code Playground...
Interview Questions
basic
- How do you read the JSON body sent by a client in a `POST` request?
intermediate
- How do you read a query parameter (like `?id=5`) from a `NextRequest` object?