- 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.
推薦閱讀
- C及C++程序設計(第4版)
- MySQL數據庫管理實戰
- Kali Linux Web Penetration Testing Cookbook
- Kubernetes實戰
- Git高手之路
- JavaScript動態網頁開發詳解
- 小程序開發原理與實戰
- Responsive Web Design by Example
- 單片機應用與調試項目教程(C語言版)
- 精通Python自動化編程
- Learning OpenStack Networking(Neutron)(Second Edition)
- Arduino計算機視覺編程
- Python編程基礎教程
- Joomla!Search Engine Optimization
- Clojure for Finance