What if I want to implement a complex request in REST

I would like to implement a REST service that can parse a request, such as receiving users created after start to finish, and with administrator privilege. It seems that the standard REST implementation could only request IDs. Do I need a certain protocol for myself to make such a request possible or any standard?

Thanks!

+6
rest
source share
5 answers

Take a look at the Google GDATA Protocol . This is very RESTful , and they have a very good way to execute complex queries, while maintaining a clean URI.

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

Here is an example of what their pure request URIs are

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

instead

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

From Google:

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

+1
source share

There are no restrictions in REST that say that you can only request IDs. There is nothing wrong with using a set of query parameters to return a set of users matching these search criteria.

+3
source share

As far as I understand, calming things are valid for CRUD actions. You can implement a separate / url search method and pass as many parameters to it as you need. And if you are still trying to stick to REST methodologies - you should use the GET request type.

0
source share

Ryan Bates has a Railscast where he shows creating searches as a resource. The concept is still valid even if you are not doing Rails.

http://railscasts.com/episodes/111-advanced-search-form

0
source share

I take the django field search semantics as a guide for complex searches. https://docs.djangoproject.com/en/dev/ref/models/querysets/#id4

You should not be distracted by the fact that it is defined as an api for lanuage, it is easy to translate it into html request parameters.

An example would be http://example.com/Goods?category=fruit&size__lt=14

Get the result select * from goods where category = 'fruit' and size < 14 in sql or /goods[@category='fruit' and @size < 14] in xpath or whatever.

0
source share

All Articles