具有多个查询参数的Express

具有多个查询参数的Express

本文介绍了Node.js:具有多个查询参数的Express app.get的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询yelp api,并具有以下路由:

  app.get(/ yelp / term /:term / location /:location,yelp.listPlaces)

当我发出GET请求



http:// localhost:3000 / yelp?term = food& location = austin



我收到错误

 不能GET / yelp?term = food& amp; amp; 

解决方案

您是否尝试过这样调用?

  http:// localhost :30000 / yelp / term / food / location / austin 

您需要调用的URL通常看起来很漂亮很像路线,您也可以将其更改为:

  / yelp /:location /:term 

让它有点漂亮:

  http:// localhost:30000 / yelp / austin / food 


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?

解决方案

Have you tried calling it like this?

http://localhost:30000/yelp/term/food/location/austin

The URL you need to call usually looks pretty much like the route, you could also change it to:

/yelp/:location/:term

To make it a little prettier:

http://localhost:30000/yelp/austin/food

这篇关于Node.js:具有多个查询参数的Express app.get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:00