我正在使用Express with Node,我要求用户可以将URL请求为:http://myhost/fruit/apple/red.
这样的请求将返回JSON响应.
上述调用之前的JSON数据如下所示:
{
"fruit": {
"apple": "foo"
}
}
Run Code Online (Sandbox Code Playgroud)
根据上述请求,响应JSON数据应为:
{
"apple": "foo",
"color": "red"
}
Run Code Online (Sandbox Code Playgroud)
我已经配置了快递路线如下:
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*/
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我不确定如何传递多个参数,也就是说,我不确定这是否/fruit/:fruitName/:fruitColor是正确的方法.是吗?