12 - Get Data from POST Requests - Basic Node and Express - freeCodeCamp Tutorial
Ganesh H
We can retrieve the data that body-parser captured from the form during a POST request from the request's body field. This is done by setting up a POST route for the form, running the urlencoded function, followed by our own middleware function.
Link to challenge : https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/get-data-from-post-requests Written Guide : https://www.notion.so/ganeshh123/Get-Data-from-POST-Requests-becb31b940214d35ae096a2ffa94de33
Full Playlist for this course : https://www.youtube.com/playlist?list=PLhGp6N0DI_1SdIZ3uhbXnKAq2UcICSnWS All Writen Guides for this course : https://www.notion.so/ganeshh123/dab5e189407244c793c2f32d066eee9f All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganesh-H-293ea420d34a464f9a1907e0405b5f26
Concepts: bodyParser.urlencoded() Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings. A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true). https://github.com/expressjs/body-parser#bodyparserurlencodedoptions
request.body Contains key-value pairs of data submitted in the request body. By default, it is undefined, and is populated when you use body-parsing middleware such as express.json() or express.urlencoded(). https://expressjs.com/en/api.html#req.body
app.post() Routes HTTP POST requests to the specified path with the specified callback functions. https://expressjs.com/en/api.html#app.post.method
Middleware Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next. http://expressjs.com/en/guide/using-middleware.html
response.json() Sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using JSON.stringify(). The parameter can be any JSON type, including object, array, string, Boolean, number, or null, and you can also use it to convert other values to JSON. https://expressjs.com/en/api.html#res.json
-————————————————————————————————————- Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js lets developers use JavaScript t ... https://www.youtube.com/watch?v=9zqOoBAEuEg
19956871 Bytes