- 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.
推薦閱讀
- 微服務設計(第2版)
- Java面向對象思想與程序設計
- JMeter 性能測試實戰(第2版)
- Apache Spark 2 for Beginners
- 營銷數據科學:用R和Python進行預測分析的建模技術
- Java設計模式及實踐
- Visual Basic學習手冊
- 零基礎學Python數據分析(升級版)
- Visual C++應用開發
- C語言程序設計教程
- MongoDB,Express,Angular,and Node.js Fundamentals
- Developing SSRS Reports for Dynamics AX
- Modern C++ Programming Cookbook
- 移動增值應用開發技術導論
- 機器學習微積分一本通(Python版)