Receiving HTTP POST requests
The HTTP POST
method is employed for transmitting data to the server, in contrast to the HTTP GET
method, which is utilized to retrieve data.
To be able to receive POST
data, we need to instruct our server on how to accept and handle POST
requests. A POST
request typically contains data within the body of the request, which is sent to the server to be handled. The submission of a web form is typically done via an HTTP POST
request.
Important note
In PHP, it is possible to access POST
data via a $_POST
array. PHP does not follow the non-blocking architecture that Node.js does, which means that the PHP program would wait or block until the $_POST
values are populated. Node.js, however, provides asynchronous interaction with HTTP data at a lower level, which allows us to interface with the incoming message body as a stream. This means that the handling of the incoming stream is within the developer’s control and concern.
In this recipe,...