Once a request is processed, a response must be returned to the client to inform it of what happened. To build a response for the client, several pieces of information are required. One of these pieces of information is the HTTP response status code, which is responsible for indicating whether a specific HTTP request has been successfully completed.
Response status codes are grouped into five classes:
1) Informational: Range from
2) Successful: Range from
3) Redirects: Range from
4) Client Errors: Range from
5) Server Errors: Range from
Each response status code conveys information about what happened during the processing of the request, which in turn helps the client decide how to handle the response and if further action is necessary. Status codes are paired with a short text-based description to help elucidate the meaning of the code. Some common types of status codes that you are likely to encounter are
400 Bad Request, and
500 Internal Server Error.
The server code to the right handles
POST requests. The
GET request handler is returning data successfully to the client and needs a status code to indicate this success.
handleGetRequest() function, set the status code on the server response to the appropriate status code indicating success.
GET requests, the
POST requests are failing. In the
POST request handler code, set the status code on the server response to the appropriate status code indicating an internal server error.
Run your code with
node app.js, then click on the “Check Work” button.