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

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.

主站蜘蛛池模板: 张家川| 阿勒泰市| 邵武市| 徐汇区| 元阳县| 佛教| 郴州市| 霍林郭勒市| 富裕县| 珠海市| 延安市| 喀喇沁旗| 陆河县| 芜湖县| 丹阳市| 梁河县| 鹤岗市| 申扎县| 淮滨县| 房产| 明星| 惠安县| 潼南县| 修武县| 葫芦岛市| 柞水县| 卢湾区| 富锦市| 将乐县| 沙田区| 和顺县| 大新县| 永登县| 西华县| 万盛区| 青阳县| 鄱阳县| 东乡| 临高县| 资源县| 鄂伦春自治旗|