-2

I have create a mean stack app. In this app when we search something I am parsing a parameters to the back-end from the front end which has been created using angular 2.

router.get('/search/:search', (req, res) => {

In this the value is the search keyword.

This is not the REST URL format right?

How do I make it look like a rest URL? Something like this?

/cars?color=blue&type=sedan&doors 
ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
  • Possible duplicate of [How to get GET (query string) variables in Express.js on Node.js?](https://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-express-js-on-node-js) – jonrsharpe Jul 30 '17 at 17:37

1 Answers1

0
req.query

Contains all of the values passed to the GET request.

For your example it would look like this:

router.get('/cars', (req, res) => {
    req.query.color // = blue
    req.query.type // = sedan
    req.query.doors // = undefined bec there is no value
}

http://expressjs.com/en/api.html#req.query

Moshe Karmel
  • 459
  • 4
  • 9