if the content-type of the POST request is application/json, "mylist" would actually be yet parsed into request.post_vars (i.e. you can skip body.read())
On Thursday, October 23, 2014 1:24:09 AM UTC+2, Henry Nguyen wrote: > > For posterity's sake, I was able to retrieve the array in the request body > by using: > > import json > my_list = json.loads(request.body.read()) > > and then iterating through the list items just like any other list. This > was taken from http://web2py.com/books/default/chapter/29/04#request > under request.body. > > Thanks for letting me know that request.restful() wouldn't parse it > automatically, Niphlod. > > Henry > > On Monday, October 13, 2014 12:25:54 PM UTC-7, Niphlod wrote: >> >> you have to code your own methods. >> >> On Sunday, October 12, 2014 11:32:23 PM UTC+2, Henry Nguyen wrote: >>> >>> I have a function in my controller decorated with the @request.restful() >>> decorator. I would like to be able to accept a JSON array of objects, >>> >>> [{"id": 1, "new_value": 1},{"id": 2, "new_value": 2}] >>> >>> , on a POST, PUT, or DELETE. For example, I'd like the client to be able >>> to update a series of values on one request, as opposed to having to submit >>> multiple requests for each individual update. However, the args and vars >>> parameters being passed to the methods are empty when a request is sent >>> with the JSON payload above. Specifically, args only gets populated from >>> URL args and vars only get populated if the array is accompanied by a key, >>> such as in: >>> >>> {"update": [{"id": 1, "new_value": 1},{"id": 2, "new_value": 2}]} >>> >>> While it certainly isn't too much trouble to include that initial key, I >>> was wondering if there's any way to retrieve the JSON objects from the >>> request without having to specify the key so that I could pass a simple >>> array instead? >>> >>> Thank you ahead of time for any help. >>> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.