Handling HTTP POST requests
The HTTP POST method is used to send data to the server, as opposed to the HTTP GET method, which is used to obtain data.
To be able to receive POST data, we need to instruct our server 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 the $_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, we're going to create...