I assume what you mean by rest principles is that you want to do a GET and 
not a POST. Problem is some browsers (for example IE) have limits on the 
size of the path_info in GET methods. So if you do not care about that you 
can do

.../api/available_resources?query={...}


where query here is a url-encoded jsonobject.
web2py does offer two more sophisticated mechanisms:

http://stackoverflow.com/questions/11991678/can-web2py-serve-rest-data-of-many-to-may-tables-via-parse-as-rest

https://groups.google.com/forum/#!topic/web2py/WN9yzLIfi6M


On Thursday, 21 May 2015 22:42:12 UTC-5, [email protected] 
wrote:
>
> Thanks, Massimo.  I can see how that would work well in the web2py 
> environment.
>
> In our organization, however, we have heterogeneous systems that use REST 
> interfaces to share data.  So, I am hoping to find a solution that aligns 
> as closely as possible with REST principles.
>
>
>
> On Tuesday, May 19, 2015 at 10:38:36 PM UTC-7, Massimo Di Pierro wrote:
>>
>> Hello Kevin,
>>
>> the best way is to make an Ajax request with content type 'application/json' 
>> and put the JSON search_criteria into the HTTP request body. For example:
>>
>> curl -H "Content-Type: application/json" - X POST -d "{...}" 
>> http://..../mypage
>>
>> where {...} is your JSON object. Then in the web2py app
>>
>> def mypage():
>>      data = request.post_vars
>>      ...
>>
>> data will contain the parsed JSON as a python object.
>>
>>
>>
>>
>>
>>
>> On Tuesday, 19 May 2015 19:50:22 UTC-5, [email protected] 
>> wrote:
>>>
>>> We are developing a RESTful API.  One of our use cases requires that we 
>>> query a resource with somewhat complex search criteria.  Internally, the 
>>> search criteria would be represented by a data structure similar to this:
>>>
>>> search_criteria = {'date':'5/31/2015',
>>>                    'locations':[{'location_name':'Los Angeles',
>>>                                  'attendees':10,
>>>                                  'services':['Housekeeping','Catering']
>>>                                 },
>>>                                 {'location_name':'New York',
>>>                                  'attendees':5,
>>>                                  'services':['Housekeeping']
>>>                                 }
>>>                    ],
>>>                    'duration':60
>>>
>>> }
>>>
>>>
>>> What would be a recommended strategy for passing complex query parameters 
>>> to a RESTful API built with web2py?
>>>
>>>
>>> Our short term solution has been to provide simple query parameters that 
>>> can contain delimited values.  For example:
>>>
>>>
>>>     GET  .../api/available_resources/?date=2015-05-31&locations=Los 
>>> Angeles|New 
>>> York&attendees=10|5&services=Housekeeping,Catering|Housekeeping&duration=60
>>>
>>>
>>> But, this seems less than ideal.  It is not intuitive that Los Angeles 
>>> should be associated with 10 attendees and the two specified services.
>>>
>>>
>>> Options we have considered include:
>>>
>>>
>>>    - Treating the search criteria as a resource.  Thus, we would first POST 
>>> the complex search criteria and receive a handle in return.  Then, we would 
>>> GET available_resources, passing the search criteria handle.  (This seems 
>>> to be messy regarding how to handle the search criteria.  Is it stored 
>>> statefully in the session?  Is it written to the database?  When would it 
>>> get cleaned up?)
>>>    - Treat the search as a command.  We would POST a resource search 
>>> command with a JSON representation of the search criteria in the body.  
>>>    - Implement oData parsing for the query string.  (While it is true that 
>>> oData syntax could be constructed to meet the needs, yikes!, that's a lot 
>>> of overhead for the API consumer and the API parser.)
>>>
>>> Are any of these considered best practice?  Or, is there yet another 
>>> strategy that we could consider?
>>>
>>> Many thanks for your help!
>>>
>>> Kevin
>>>
>>>
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to