Understanding HTTP requests
Node.js represents HTTP requests using the IncomingMessage
class, which is defined in the http
module. The four main building blocks of an HTTP request are:
- The HTTP method, which describes the operation the client wants to perform.
- The URL, which identifies the resource the request should be applied to.
- The headers, which provide additional information about the request and the capabilities of the client.
- The request body, which provides the data required for the requested operation.
The IncomingMessage
class provides access to all of these building blocks, allowing them to be inspected so the server can generate a suitable response. Table 5.6 lists the properties provided for the first three request building blocks, and I explain how to deal with the request body in Chapter 6.
Table 5.6: Useful IncomingMessage properties
Name |
Description... |