On Thursday, May 21, 2015 at 8:42:12 PM UTC-7, 
[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.
>
>
JSON appears to align with REST principle.  From Wikipedia:
"Unlike SOAP <http://en.wikipedia.org/wiki/SOAP>-based web services, there 
is no "official" standard for RESTful web APIs.[10] 
<http://en.wikipedia.org/wiki/Representational_state_transfer#cite_note-Elkstein-10>
 
This is because REST is an architectural style, while SOAP is a protocol. 
Even though REST is not a standard *per se*, most RESTful implementations 
make use of standards such as HTTP <http://en.wikipedia.org/wiki/HTTP>, URI 
<http://en.wikipedia.org/wiki/URI>, JSON <http://en.wikipedia.org/wiki/JSON>, 
and XML <http://en.wikipedia.org/wiki/XML>." 
<http://en.wikipedia.org/wiki/Representational_state_transfer#cite_note-Elkstein-10>
<URL:en.wikipedia.org/wiki/Representational_state_transfer>

However, your resources may already use a defined API in a non-JSON form.  
RedHat, for instance, has a RESTful storage API that uses XML.
In the Web2Py book, chapter 10 has a section on XMLRPC that may be helpful, 
as well as the REST section:
<URL:http://www.web2py.com/books/default/chapter/29/10/services#Restful-Web-Services>

If the resources are not yet defined, you have the option of choosing any 
of above choices, and perhaps others, as fits your needs,
while still being RESTful. 

/dps



 

>
>
> 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