Excercise tracker GET users's exercise log:

GET /api/exercise/log?{userId}[&from][&to][&limit]
first why is that so? it is some standart?
2. the ? say it is query, but the rest is not, because they don’t have =
If I try some tricks, like userID={} or query[0], I get Cannot GET /api/exercise/log
inspired by

Route path: /flights/:from-:to
Request URL: http://localhost:3000/flights/LAX-SFO
req.params: { "from": "LAX", "to": "SFO" }
  1. if I use a params I get empty array
app.get("/api/exercise/log:par", function (req, res ) {
 var logs =req.params.par
  1. the same result if use req.body
1 Like

There’s no single way to do this. Query parameters are useful because they are optional. You don’t want to query to fail if it doesn’t have from or to.

You’re expected to understand that query values are set with =. Since you do understand this, I don’t see the problem.

The values are in the query object of req. So, req.query.from would give you the from query parameter.

Your URL is not correctly formatted for route parameters. You need to separate parameters with a /, /api/exercise/log/:par.

1 Like

o.k , but I pointed that solution is no one from query, params, or body parser.
do you mean is this case?

Here are some examples of route paths based on string patterns.
This route path will match acd and abcd.
app.get('/ab?cd', function (req, res) {

You don’t put the query parameters in your route definition. Query parameters are in the req.query object.

app.get('/myRoute', function(req, res) {
    var queryParam = req.query.a || "Nothing was sent";
curl http;//localhost:3000/myRoute?this%20is%20a%20message 
# "this is a message"
curl http://localhost:3000/myRoute
# "Nothing was sent"

I getting just ''log"

Can you link to your project code?

Allows us to do this:


app.route("/api/exercise/log/:a").get( function (req, res ) {
 var logs =req.query || "Nothing was sent";

:a is a route parameter, not a query parameter. Route parameters are used like this localhost:3000/api/exercise/log/123. A query parameter is used in query strings, like this localhost:3000/api/exercise/log?number=123.

req.params - route parameters
req.query - query parameters

Take a look at my glitch project I just linked.

Nothing new. The format is set by goals

GET users's exercise log: GET /api/exercise/log?{userId}[&from][&to][&limit]
{ } = required, [ ] = optional
from, to = dates (yyyy-mm-dd); limit = number

Yes. Those are all query parameters.

I cannot reach them, because they don’t have a ={userID} something like
GET /api/exercise/log?userId={userId}[& from =from][&to=to][&limit=limit]

You don’t need the brackets, and there has to be actual data in the parameters:

GET /api/exercise/log?userId=1234&from=2018-01-01&to=2018-07-23&limit=100

look at this model from freecodecamp and there is goal

GET users's exercise log: GET /api/exercise/log?{userId}[&from][&to][&limit]
{ } = required, [ ] = optional
from, to = dates (yyyy-mm-dd); limit = number

who had write that and think we allunderstand him as
that is really mean trick