【发布时间】:2013-02-28 06:22:51
【问题描述】:
我将 Express 与 Node 一起使用,并且我有一个要求,用户可以将 URL 请求为:http://myhost/fruit/apple/red。
这样的请求将返回 JSON 响应。
上述调用之前的 JSON 数据如下所示:
{
"fruit": {
"apple": "foo"
}
}
对于上面的请求,响应的 JSON 数据应该是:
{
"apple": "foo",
"color": "red"
}
我已将 express 配置为如下路由:
app.get('/fruit/:fruitName/:fruitColor', function(request, response) {
/*return the response JSON data as above using request.params.fruitName and
request.params.fruitColor to fetch the fruit apple and update its color to red*/
});
但这不起作用。我不确定如何传递多个参数,也就是说,我不确定/fruit/:fruitName/:fruitColor 是否是正确的方法。是吗?
【问题讨论】: