2018-10-12 15:37:13 -04:00
---
title: Get Query Parameter Input from the Client
---
2019-07-24 00:59:27 -07:00
# Get Query Parameter Input from the Client
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
2019-07-02 07:05:15 +05:30
Given the endpoint URL, `/name?first=firstname&last=lastname` , we can extract the query parameters (`first` and `last` ) and their corresponding values from the `req.query` object and send a custom JSON response containing values derived from the query parameters to the client.
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
2019-07-02 07:05:15 +05:30
app.get("/name", function(req, res) {
var firstName = req.query.first;
var lastName = req.query.last;
// OR you can destructure and rename the keys
var { first: firstName, last: lastName } = req.query;
// Use template literals to form a formatted string
res.json({
name: `${firstName} ${lastName}`
});
});
2018-10-12 15:37:13 -04:00
```
2019-07-24 00:59:27 -07:00
< / details >