- Building Microservices with Go
- Nic Jackson
- 150字
- 2021-07-15 17:28:15
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.
推薦閱讀
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- CentOS 7 Server Deployment Cookbook
- 跟小海龜學(xué)Python
- Hadoop+Spark大數(shù)據(jù)分析實戰(zhàn)
- Python貝葉斯分析(第2版)
- Access 2016數(shù)據(jù)庫管
- Unreal Engine 4 Shaders and Effects Cookbook
- Working with Odoo
- Babylon.js Essentials
- Mastering Git
- Android應(yīng)用開發(fā)實戰(zhàn)
- Swift語言實戰(zhàn)晉級
- 深入理解BootLoader
- 零基礎(chǔ)學(xué)C語言(升級版)
- Python計算機(jī)視覺和自然語言處理