开发者

RESTful URLs for a search service with an arbitrary number of filtering criteria

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-RESTfu开发者_JAVA技巧l, 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜