REST API过滤器运营商的最佳实践 [英] REST API filter operator best practice
问题描述
我建立一个使用过滤器
参数来控制搜索结果中的REST API。例如,人们可以通过调用搜索用户:
I am building a REST API that uses a filter
parameter to control search results. E.g., one could search for a user by calling:
GET /users/?filter=name%3Dfoo
现在,我的API应该允许许多不同的过滤器
运营商。 数值运算符,如等于
,比
,大于小于
,字符串操作符如包含
,与
开始或与
和日期运算结束,如
或 timeDiff的
。此外,和
和或
组合应该是可能的。结果
基本上,我想支持底层MySQL数据库运营商的一个子集。
Now, my API should allow many different filter
operators. Numeric operators such as equals
, greater than
, less than
, string operators like contains
, begins with
or ends with
and date operators such as year of
or timediff
. Moreover, AND
and OR
combinations should be possible.
Basically, I want to support a subset of the underlying MySQL database operators.
我发现了很多不同的实现(两个很好的例子是<一个href=\"https://developers.google.com/analytics/devguides/reporting/core/v3/reference?hl=de#filters\">Google分析和<一个href=\"http://lj.platformatyourservice.com/wiki/REST_API:Filter_Ex$p$pssions_in_REST_APIs\">LongJump)似乎使用自定义的语法。结果
看着我的要求,我可能会设计一个自定义的语法为pretty类同MySQL的运算符的语法。结果
但是,我想知道是否有任何最佳做法,确定了我应该遵循和我是否应该考虑别的。谢谢!
I found a lot of different implementations (two good examples are Google Analytics and LongJump) that seem to use custom syntax.
Looking at my requirements, I would probably design a custom syntax pretty similiar to the MySQL operator syntax.
However, I was wondering if there are any best practices established that I should follow and whether I should consider anything else. Thanks!
推荐答案
您可以检查 BreezeJs 太多,看看这个协议,这对Node.js的MongoDB的+与微风MongoDB的模块和一个实现。使用Web API和NET的EntityFramework项目,Breeze.ContextProvider DLL。
You can check BreezeJs too and see how this protocol it's implemented for node.js + mongodb with breeze-mongodb module and for a .NET project using Web API and EntityFramework with Breeze.ContextProvider dll.
这篇关于REST API过滤器运营商的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!