I am using Express with Node and I have a requirement in which the user can request the URL as: http://myhost/fruit/apple/red
.
Such a request will return a JSON response.
The JSON data, before the above call looks like:
{
"fruit": {
"apple": "foo"
}
}
With the above request, the response JSON data should be:
{
"apple": "foo",
"color": "red"
}
I have configured express to route as follows:
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*/
});
But this does not work. I am unsure of how to pass multiple parameters, that is, I am unsure if /fruit/:fruitName/:fruitColor
is the correct way to do this. Is it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…