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

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.

主站蜘蛛池模板: 西昌市| 沈丘县| 四川省| 桃源县| 正宁县| 新野县| 武陟县| 吉安市| 武义县| 长春市| 观塘区| 双桥区| 兖州市| 喀喇沁旗| 依安县| 天柱县| 望江县| 渭南市| 全南县| 三明市| 措勤县| 汝南县| 兴业县| 葵青区| 喀喇沁旗| 华安县| 龙陵县| 丰镇市| 宿州市| 双牌县| 吉木萨尔县| 长沙市| 阳朔县| 神木县| 汝州市| 株洲县| 平度市| 阳春市| 洞口县| 建昌县| 敦化市|