Parsing the HTTP request body
body-parser
is a middleware function that parses the incoming request body and makes it available in the request
object as request.body
https://expressjs.com/en/resources/middleware/body-parser.html.
This module allows an application to parse the incoming request as:
- JSON
- Text
- Raw (buffer original incoming data)
- URL encoded form
The module supports automatic decompression of gzip and deflates encodings when the incoming request is compressed.
Getting ready
In this recipe, you will see how to use the body-parser
NPM module to parse the content body sent from two different forms encoded in two different ways. Before you start, create a new package.json
file with the following content:
{ "dependencies": { "body-parser": "1.18.2", "express": "4.16.3" } }
Then, install the dependencies by opening a terminal and running:
npm install
How to do it...
Two forms will be displayed to the user, both of them will send data to our web server application encoded...