Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What if I want to implement a complicated query in REST

Tags:

rest

I would like to implement a REST service which is able to parse query such as retrieving the users created after startdate and before endate and with the privilege of admin. It seems that standard REST implementation could only query by ID. Do I need to self-defined protocol to make this kind of query possible or any standard?

Thanks!

like image 235
xiao 啸 Avatar asked Jan 17 '10 08:01

xiao 啸


2 Answers

There is no constraint in REST that says you can only query by ID. There is absolutely nothing wrong with using a set of query parameters to return a set of users that match those search criteria.

like image 54
Darrel Miller Avatar answered Sep 28 '22 08:09

Darrel Miller


Take a look at Google's GDATA Protocol. It's very RESTful and they have a very nice way of performing "complex" queries while still keeping a clean URI.

http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries

Here is an example of what their clean query URIs

http://example.com/jo/-/Fritz/2006

instead of

http://example.com/jo?category=Fritz&category=2006

From Google:

This approach identifies a resource without using query parameters, and it produces cleaner URIs. We chose this approach for categories because we think that category queries will be the most common queries.

like image 21
nategood Avatar answered Sep 28 '22 09:09

nategood