2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Get Data from POST Requests
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Get Data from POST Requests
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
Just like using req.query we can do req.body to get our data. This challenge is very similar to "Get Query Parameter Input from the Client."
|
|
|
|
|
|
|
|
In order to get data from a post request a general format is:
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
app.post(PATH, function(req, res) {
|
|
|
|
// Handle the data in the request
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2019-02-21 23:02:41 +05:30
|
|
|
```javascript
|
2019-07-24 00:59:27 -07:00
|
|
|
app.post("/name", function(req, res) {
|
2019-02-21 23:02:41 +05:30
|
|
|
// Handle the data in the request
|
2019-07-24 00:59:27 -07:00
|
|
|
var string = req.body.first + " " + req.body.last;
|
|
|
|
res.json({ name: string });
|
2019-02-21 23:02:41 +05:30
|
|
|
});
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|