At the moment, my (pretty standard) REST interface looks like this:
POST /foo # creates a new foo
PUT /foo/{id} # updates a specific foo
GET /foo/{id} # returns a specific foo
GET /foo # returns a collection of foos
Only authenticated clients are able to use these operations. When using GET
or PUT
, clients can only retrieve or manipulate their own foo instances. So calling GET /foo
only returns a list of foos of a particular user, not all existing foos.
What I want to do now is to introduce a REST compliant search. Usually you just would add parameters to the URI, something like this:
GET /foo?param1=val1¶m2=val2&...
However, in this case, I want clients to be able to search all foos and therefore retrieve foos that don't necessarily belong to them. Of course the resource representations would look a bit different, without any sensible client specific data.
Why would I want to do that, what's the purpose?
Imagine an online auction for cars. A user should be able to get a list of own active auctions (cars he/she wants to sell) using GET /cars
. On the other hand, users that are looking for a car should be able to perform a search, something like GET /cars?color=metallic-blue
.
But I think it's not a good idea to use the same URI for both the search and the the listing of own auctions (altough bot operations return cars), mainly because the resource representations of the response would slightly differ (e.g. the search returns a more general result without any sensible data). But how else could I do it? Just introducing a new URI, maybe something like GET /cars/search?..
?
GET /my/cars
for own cars andGET /cars?
for search. You may also find that you'll need to differentiate between listings and owned cars not for sale, for example, if people are allowed to document their garage.