官术网_书友最值得收藏!

Sorting

Like limiting the response, sorting is a good strategy to leverage when API design is being done. In general, what the end user will see is just a new query parameter called sort, which tells the service which fields should be used for the sorting strategy. Also, the URI may contain information about the sorting strategy, such as ascending, descending, and so on.

The value of the sort parameter is a comma-separated list of sort keys, like a map. Likewise, sort directions can be appended to each sort key pair, separated by the : character:

https://<URI>/items/sort=name,description,size

In this example, the services will sort everything based on the first key, which is name; then, the services will sort by the description field, and finally, by the size field. The supported sort directions are either asc for ascending or desc for descending:

https://<URI>/items?sort=name:asc,description,size
https://<URI>/items?sort=name:asc,description:desc,size
https://<URI>/items?sort=name:asc,description:asc,size
https://<URI>/items?sort=name,description:asc,size
https://<URI>/items?sort=name:asc,description,size:desc

A sort direction may be (optionally) given by the caller for each key. However, if it's not provided, a default will be set by the server, which is the one that's implemented by the backend service if nothing is provided through the URI.

主站蜘蛛池模板: 静安区| 彰化市| 庆云县| 公安县| 文化| 霞浦县| 卢龙县| 蒙山县| 罗源县| 宜黄县| 昌宁县| 水富县| 石狮市| 治县。| 昭平县| 炎陵县| 永安市| 大兴区| 开鲁县| 桐乡市| 福州市| 荣昌县| 蓝田县| 蒙山县| 星子县| 湖南省| 南康市| 报价| 景东| 内江市| 蓬安县| 宁晋县| 凤冈县| 承德县| 克东县| 昭通市| 颍上县| 手游| 天峨县| 民勤县| 嘉荫县|