Handling POST Body Data
Another very common use for Express middleware is to handle body data inside a POST request. The data inside a request body can be in various formats, such as POST parameter strings, JSON strings, or raw data. Express’s body-parser middleware attempts to parse the data in the JSON data in the body of requests and properly format them as the req.body property of the Request object.
For example, if this middleware receives POST parameters or JSON data, it converts them to a JavaScript object and stores it as the req.body property of the Request object. Listing 19.4 illustrates using the body-parser middleware to support reading form data posted to the server.
The code in lines 5–11 handles the GET request and responds with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access