Node.js : Express app.get with multiple query parameters

前端 未结 3 1447
渐次进展
渐次进展 2021-02-06 03:28

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

3条回答
  •  眼角桃花
    2021-02-06 04:25

    In the requested url http://localhost:3000/yelp?term=food&location=austin

    • base url/address is localhost:3000
    • route used for matching is /yelp
    • querystring url-encoded data is ?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 :

    • use app.get("/yelp") and extract the term and location from req.query like req.query.term
    • use app.get("/yelp/term/:term/location/:location") but modify the url accordingly as luto described.

提交回复
热议问题