tld*_*ldr 9 get node.js query-string express
我想查询yelp api,并有以下路由:
app.get("/yelp/term/:term/location/:location", yelp.listPlaces)
Run Code Online (Sandbox Code Playgroud)
当我向GET请求时
http://localhost:3000/yelp?term=food&location=austin,
我收到了错误
Cannot GET /yelp?term=food&location=austin
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
lut*_*uto 13
你试过这样称呼它吗?
http://localhost:30000/yelp/term/food/location/austin
Run Code Online (Sandbox Code Playgroud)
您需要调用的URL通常与路径非常相似,您也可以将其更改为:
/yelp/:location/:term
Run Code Online (Sandbox Code Playgroud)
为了让它更漂亮:
http://localhost:30000/yelp/austin/food
Run Code Online (Sandbox Code Playgroud)
use*_*109 10
在请求的网址中 http://localhost:3000/yelp?term=food&location=austin
localhost:3000/yelp?term=food&location=austin即数据是否一切都在之后?在执行这些匹配时不考虑查询字符串,例如"GET /"将匹配以下路由,"GET /?name = tobi"也是如此.
所以你应该:
req.query.term