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

Filtering

When we looked at RESTful APIs we discussed the concept of using the query string to perform filtering actions such as:

  • Paging
  • Filtering
  • Sorting

Obviously, if we are writing an RPC API, we do not have the luxury of a query string; however, implementing these concepts is incredibly useful. As long as we are consistent there is no reason at all that we cannot define a parameter on our request object for the filter condition:

{
"jsonrpc": "2.0",
"method": "Users.v1.GetUserLog",
"params": {
"name": "Nic Jackson",
"id": 12335432434,
"filter": {
"page_start": 1, //optional
"page_size" : 10, //optional
"sort": "name DESC" //optional
},
"id": 1
}

This is just an example and you will probably choose to implement something specific to your own needs, however, the key is consistency. If we use this same object for every method, we can be reasonably sure that our users will be cool with this.

主站蜘蛛池模板: 无极县| 象州县| 青川县| 贡嘎县| 昆明市| 澄迈县| 南京市| 搜索| 塔城市| 正安县| 河南省| 七台河市| 门头沟区| 黑河市| 子洲县| 南安市| 泾川县| 方城县| 嘉义市| 福州市| 华坪县| 沧源| 垦利县| 翁牛特旗| 黔西县| 岑溪市| 衡水市| 万年县| 浦县| 社旗县| 广平县| 通榆县| 黑山县| 乌鲁木齐县| 新津县| 澎湖县| 大新县| 五大连池市| 鹤庆县| 六安市| 论坛|