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

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.

主站蜘蛛池模板: 邯郸县| 江北区| 四子王旗| 河源市| 闽侯县| 永寿县| 濮阳县| 兰西县| 墨竹工卡县| 连江县| 扎囊县| 阿荣旗| 宜丰县| 玛曲县| 清流县| 红河县| 方山县| 开平市| 贵阳市| SHOW| 苍山县| 东兰县| 达日县| 九龙县| 博爱县| 樟树市| 黎川县| 开化县| 金山区| 普陀区| 集贤县| 改则县| 小金县| 重庆市| 文昌市| 宜阳县| 惠东县| 绥化市| 修文县| 油尖旺区| 铁岭县|