我想查询yelp api,并有以下路线:
app.get("/yelp/term/:term/location/:location", yelp.listPlaces)
当我向
http://localhost:3000/yelp?term=food&location=austin
,
我得到错误
Cannot GET /yelp?term=food&location=austin
我究竟做错了什么?
我想查询yelp api,并有以下路线:
app.get("/yelp/term/:term/location/:location", yelp.listPlaces)
当我向
http://localhost:3000/yelp?term=food&location=austin
,
我得到错误
Cannot GET /yelp?term=food&location=austin
我究竟做错了什么?
你试过这样称呼它吗?
http://localhost:30000/yelp/term/food/location/austin
您需要调用的 URL 通常看起来很像路由,您也可以将其更改为:
/yelp/:location/:term
为了让它更漂亮一点:
http://localhost:30000/yelp/austin/food
在请求的网址中http://localhost:3000/yelp?term=food&location=austin
localhost:3000
/yelp
?term=food&location=austin
ie 之后的所有数据?执行这些匹配时不考虑查询字符串,例如“GET /”将匹配以下路由,“GET /?name=tobi”也是如此。
所以你应该:
req.query.term
我想添加到@luto 的答案。无需在路由中定义查询字符串参数。例如,路由/a
将处理对/a?q=value
.
url 参数是为路由模式定义所有匹配项的快捷方式,因此路由/a/:b
将匹配
/a/b
/a/c
/a/anything
它不匹配
/a/b/something
或者/a