📜  req.query 与 req.params express - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:32.131000             🧑  作者: Mango

代码示例1
Passing params ===> GET request to "/cars/honda" 
returns a list of Honda car models


Passing query =====> GET request to "/car/honda?color=blue"


returns a list of Honda car models, but filtered so only models with an stock
color of blue are returned.

It doesn't make sense to add those filters into the URL 
parameters (/car/honda/color/blue) because according to REST, that would 
imply that we want to get a bunch of information about the color "blue".
Since what we really want is a filtered list of Honda models, we use query
strings to filter down the results that get returned.

Notice that the query strings are really just { key: value } pairs in a 
slightly different format: ?key1=value1&key2=value2&key3=value3.