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.