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

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.

主站蜘蛛池模板: 耒阳市| 元氏县| 二连浩特市| 玛纳斯县| 平罗县| 峨眉山市| 沅江市| 科技| 天峨县| 安平县| 兴国县| 文昌市| 涞水县| 邹城市| 健康| 新安县| 乃东县| 丹江口市| 贡觉县| 前郭尔| 嵊泗县| 景德镇市| 牟定县| 竹北市| 西城区| 沭阳县| 汪清县| 漳平市| 尤溪县| 封丘县| 化德县| 肃北| 潜山县| 大同市| 祥云县| 宁阳县| 城步| 甘泉县| 攀枝花市| 建湖县| 巴林左旗|