定义带有或条件的查询参数的RESTful最佳实践是什么? [英] What are the RESTful best practices on defining a query parameter with an or condition?

查看:714
本文介绍了定义带有或条件的查询参数的RESTful最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,遵循RESTful最佳实践,我应该以哪种方式定义如下所示的url:

I would like to know, following RESTful best practices in which ways should I define an url like the following:

/people?q="email=aa@aa.com||phone=11111"

关键是要根据他们在搜索框中插入的内容,通过电子邮件地址或电话来搜索该人.

The point would be to search for a person either by their email address or phone depending on what they've inserted on a search box.

我一直在阅读一些有关使用RESTful服务的最佳实践的指南,但似乎没有人谈论这种情况.

I've been reading a few guides on best practices in using RESTful services but none seem to talk about this situation.

推荐答案

REST 表示您遵循通过构建(统一)应用程序接口来实现标准.

REST means you follow standards by building the (uniform) application interface.

当前,尚无用于使用GET进行常规查询的标准解决方案.您可以使用许多非标准的URL查询语言.例如. RQL mongodb ,等等.因此,请不要重蹈覆辙.或者,您可以像在示例中一样在查询参数中发送序列化查询.它可以使用任何标准查询语言,例如 SPARQL (如果您将REST与 hydra .如果不这样做,则必须在供应商MIME类型的文档中进行描述. (在这种情况下,常规查询意味着您不知道查询的结构是什么.)

Currently there is no standard solution for general querying with GET. There are many non standard URL query languages you could use. E.g. RQL, OData, most of the structure of database REST API URIs: e.g. mongodb, etc... So try not to reinvent the wheel. As an alternative you can send a serialized query in a query param as you did in your example. It can be on any standard query language, e.g. SPARQL if you use REST with RDF vocabs like hydra. If you don't then you have to describe it in the documentation of your vendor MIME type. (General querying means in this context that you don't know what the structure of the query will be.)

如果您正在寻找非通用的查询解决方案,则可以使用任何 URI模板只要您以某种方式描述了与RDF vocab或供应商MIME类型的文档中链接的参数.如果您不明白我在说什么,请检查维基百科. (在这种情况下,非一般性查询意味着您对查询结构将有所了解,并且可以使用URI模板对其进行描述.)

If you are looking for a non-general querying solution, then you can use any URI template as long as you describe somehow the parameters of your link with your RDF vocab or in the documentation of your vendor MIME type. If you don't understand what I am talking about, check the uniform interface constraint / self-descriptive message, HATEOAS sections of the manual or use wikipedia. (Non-general querying means in this context that you have an idea about what the query structure will be and you can describe it with URI templates.)

请注意,您必须解析,验证和授权这些查询,因此发送SQL语句并通过数据库运行它而不进行任何检查可能对您的应用程序是致命的.

Be aware that you have to parse and validate and authorize these queries, so sending an SQL statement and running it through the database without any check can be fatal to your application.

这篇关于定义带有或条件的查询参数的RESTful最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆