Excercise tracker GET users's exercise log:

Excercise tracker GET users's exercise log:
0

#1

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

#2

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.


#3

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) {
  res.send('ab?cd')
})

#4

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";
    res.send(queryParam);
});
curl http;//localhost:3000/myRoute?this%20is%20a%20message 
# "this is a message"
curl http://localhost:3000/myRoute
# "Nothing was sent"

#5

I getting just ''log"


#6

Can you link to your project code?


#8

Allows us to do this:

https://sunrise-cover.glitch.me/api/exercise/log?a=hi%20lubodrinka


#10
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.


#11

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

#12

Yes. Those are all query parameters.


#13

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]


#14

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

#15

https://fuschia-custard.glitch.me/
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
https://fuschia-custard.glitch.me/api/exercise/log?userId=SyKsUMHNm&from=2014-01-08&to=2018-07-24&limit=5
that is really mean trick