具有任意数量过滤条件的搜索服务的 RESTful URL

发布于 2024-08-13 06:33:18 字数 628 浏览 1 评论 0原文

我想构建一个 RESTful Web 服务,实现生物数据数据库的搜索界面。

典型的搜索请求可能涉及十几个左右的数据属性。 例如,按学名搜索,将搜索限制在水深小于100m的范围内。 我的第一直觉是拥有查询字符串中的所有属性 例如 ?searchType=sciname&sciname=mola+mola&maxdepth=100&mindepth=0

但是,查询字符串被视为非 RESTful,请参阅 http://rest.blueoxen.net/cgi-bin/wiki.pl?QueryStringsConsideredHarmful

我看过一些早期的 SO 讨论,例如 用于搜索的 RESTful URL 设计 我仍然不清楚这一点,所以我的问题是:

搜索服务的 RESTful URL 是否有一个可接受的标准或模式,其中可能有任意数量 过滤值?

I want to build a RESTful web service that implements a search interface for a database of biological data.

A typical search request could involve a dozen or so attributes of the data.
For example, search by scientific name, constrain the search to water depths less than 100m.
My first instinct is to have all of the attributes in the query string
e.g. ?searchType=sciname&sciname=mola+mola&maxdepth=100&mindepth=0

However, query strings are considered non-RESTful, see http://rest.blueoxen.net/cgi-bin/wiki.pl?QueryStringsConsideredHarmful

I have looked at some earlier SO discussions such as RESTful URL design for search
and I'm still not clear on this point, so my question:

Is there an accepted standard or pattern for RESTful URLs for a search service where there may be an arbitrary number
of filtering values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2024-08-20 06:33:18

在 Web 的 REST 风格中:

  • request-uri 的 path 组件标识特定资源。
  • 请求 uri 的查询字符串组件标识在呈现该资源时所做的任何特定过滤器或更改。
  • Accept 标头标识应在其中呈现按指定过滤的给定资源的特定内容类型。
  • Accept-Language 标头标识了一种特定语言,应使用该特定语言来呈现按指定过滤的给定资源。

所以回答你的问题:

GET /species?searchType=sciname&sciname=mola+mola&maxdepth=100&mindepth=0

完全合适。

In the REST style of the Web:

  • The path component of the request-uri identifies a particular resource.
  • The query-string component of the request-uri identifies any particular filters or alterations done when presenting that resource.
  • The Accept header identifies a particular content-type in which the given resource, filtered as specified, should be presented.
  • The Accept-Language header identifies a particular language in which the given resource, filtered as specified, should be presented.

So to answer your question:

GET /species?searchType=sciname&sciname=mola+mola&maxdepth=100&mindepth=0

is perfectly appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文