Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

45 lines
959 B
Markdown

---
title: Get Route Parameter Input from the Client
---
# Get Route Parameter Input from the Client
---
## Problem Explanation
If someone tells you to build a GET or POST endpoint you would achieve the same using `app.get(...)` or `app.post(...)` accordingly.
---
## Hints
## Hint #1
In order to get route parameters from a POST request, the general format is as follows:
```javascript
app.post("/:param1/:param2", (req, res) => {
// Access the corresponding key in the req.params
// object as defined in the endpoint
var param1 = req.params.parameter1;
// OR use destructuring to get multiple paramters
var { param1, param2 } = req.params;
// Send the req.params object as a JSON Response
res.json(req.params);
});
```
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
app.get("/:word/echo", (req, res) => {
const { word } = req.params;
res.json({
echo: word
});
});
```
</details>