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

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.

主站蜘蛛池模板: 阿坝县| 阳城县| 泸溪县| 府谷县| 东阿县| 东阳市| 青浦区| 杭州市| 贵南县| 慈溪市| 册亨县| 阜新| 台安县| 建平县| 中山市| 灵山县| 玉门市| 长阳| 肃南| 宜川县| 隆德县| 彰化县| 敦煌市| 阳山县| 原阳县| 武隆县| 潮州市| 青阳县| 桓仁| 宁远县| 连平县| 收藏| 克山县| 大英县| 大同市| 岳普湖县| 沅陵县| 和平县| 昌都县| 咸阳市| 交口县|