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

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.

主站蜘蛛池模板: 叙永县| 连云港市| 克什克腾旗| 禄丰县| 镇康县| 塘沽区| 措美县| 濉溪县| 铁岭县| 安顺市| 永定县| 轮台县| 乐平市| 德庆县| 西丰县| 荆门市| 彩票| 淮阳县| 曲麻莱县| 双柏县| 察隅县| 扎鲁特旗| 广宁县| 鹤峰县| 陆丰市| 九寨沟县| 临西县| 寻甸| 定襄县| 七台河市| 云和县| 曲沃县| 云龙县| 上杭县| 通山县| 启东市| 南投县| 望都县| 麦盖提县| 兴义市| 奈曼旗|