简体   繁体   English

REST API url 滤波设计

[英]REST API url filtering design

I've been looking around and most folks seem to recommend designing filtering with ranges in REST API URLs using the bracket notation (eg /resource?weight[gte]=1&weight[lte]=5 ) or some variation of this...我一直在环顾四周,大多数人似乎建议在 REST API URL 中使用括号表示法设计过滤(例如/resource?weight[gte]=1&weight[lte]=5 )或这个的一些变体......

But is there any reason we can't just use a delimiter and document the expected order in API docs?但是有什么理由我们不能只使用分隔符并在 API 文档中记录预期的顺序吗? eg /resource?weight=1_5 ...where the API docs would inform the client that pattern is min_max例如/resource?weight=1_5 ... API 文档将通知客户端模式为 min_max

Are there any pros or cons to both the above that would warrant one over the other?以上两者是否有任何优点或缺点可以保证两者之间的关系?

Are there any pros or cons to both the above that would warrant one over the other?以上两者是否有任何优点或缺点可以保证两者之间的关系?

Yes.是的。

First: the URI production rules in RFC 3986 do not permit LEFT SQUARE BRACKET and RIGHT SQUARE BRACKET in the query part of the URI - those characters have to be pct-encoded.首先: RFC 3986中的 URI 生产规则不允许在 URI 的查询部分使用左方括号和右方括号 - 这些字符必须经过 pct 编码。

Second: we don't have a good way to communicate bespoke query value delimiters to general purpose components.第二:我们没有一个很好的方法来将定制的查询值分隔符传递给通用组件。 What you are proposing to do here is analogous to having a single input control for two values - and telling the human being using the form that they should type text using a specific schema.您在这里建议做的类似于对两个值使用单个输入控件 - 并告诉使用表单的人他们应该使用特定模式键入文本。 But we really don't have a standardized language for that.但是我们真的没有一个标准化的语言。

There's already a lot of work done in standardizing URI Templates , your default options should be limited to the mechanisms described there.在标准化URI 模板方面已经做了很多工作,您的默认选项应该限于那里描述的机制。 In a code review, I'd push back against your proposal if you didn't have compelling supporting evidence ready.在代码审查中,如果您没有准备好令人信服的支持证据,我会反对您的提议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM