query params code example
Example 1: get query param javascript
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
Example 2: difference between req.query and req.params
req.params contains route parameters
(in the path portion of the URL),
and req.query contains the URL query parameters
(after the ? in the URL).
You can also use req.param(name) to look up a parameter in both places
(as well as req.body),
but this method is now deprecated.
Example 3: query parameters
Query Parameter
represented as key value pair right after the ?
https://www.google.com/search?q=iloveyou
usually used to filter the result
GET /api/spartacus/search?gender=Male&nameContains=li
if we have more than one query parameter
& is used to connect them
Also there is a Path Parameter|variable
/api/spartans/{id} /api/spartans/:id
It's used to identify single resource amonth list of resources
in above example
the id is the path parameter to identify single spartan
Example 4: req.params req.query
req.params contains route parameters (in the path portion of the URL),
and req.query contains the URL query parameters (after the ? in the URL).
You can also use req.param(name) to look up a parameter in both places (as well as req.body),