I want to query the yelp api, and have the following route:
app.get("/yelp/term/:term/location/:location", yelp.listPlaces)
When I make a GET request to
http://localhost:3000/yelp?term=food&location=austin
,
I get the error
Cannot GET /yelp?term=food&location=austin
What am I doing wrong?
In the requested url
http://localhost:3000/yelp?term=food&location=austin
localhost:3000
/yelp
?term=food&location=austin
i.e. data is everything after ?Query strings are not considered when peforming these matches, for example "GET /" would match the following route, as would "GET /?name=tobi".
So you should either :
req.query.term
Have you tried calling it like this?
The URL you need to call usually looks pretty much like the route, you could also change it to:
To make it a little prettier:
I want to add to @luto's answer. There is no need to define query string parameters in the route. For instance the route
/a
will handle the request for/a?q=value
.The url parameters is a shortcut to define all the matches for a pattern of route so the route
/a/:b
will match/a/b
/a/c
/a/anything
it wont match
/a/b/something
or/a