In the above code if you pass a list of vars explicity:

 def manage_dog():
     ....
     def PUSH(dog,name,age,birthdate):
 
db.dog[dog].update_record(name=name,age=age,birthdate=birthdate)
         return dict()
     return locals()

It would work with PUSH http://....?name=...&age=...&birthdate=....

If you want to pass data in body as xml you would not take info as
command line argument.
You would have to parse the request.body yourself using an xml parser.
So you decide the format.


On Aug 9, 8:41 pm, Tiago Rosa <tiago.str...@gmail.com> wrote:
> Hi folks,
>
> I'm trying to expose some of my app's data through a RESTful API and
> I'm having some trouble using the POST method.
>
> In this post (http://www.reddit.com/r/programming/comments/g5hxq/
> web2py_trunk_has_a_new_restful_api_that_writes_db/) and video Massimo
> introduced web2py's RESTful API with examples, so I will use them here
> to try to clarify my doubt:
>
> Here is the model:
>  db.define_table('person',Field('name'),Field('birthdate','date'))
>
> db.define_table('dog',Field('name'),Field('owner',db.person),Field('info',' 
> text'))
>  if not db(db.person).count():
>      from gluon.contrib.populate import populate
>      populate(db.person,100)
>      populate(db.dog,100)
>
> And here is the controller:
>  def manage_dog():
>      def GET(id):
>          dog = db.dog(id)
>          return dog.as_dict() if person else None
>      def POST(owner,name,info):
>          return
> db.dog.validate_and_insert(owner=owner,name=name,info=info)
>      def DELETE(dog)
>          del db.dog(dog)
>          return dict()
>      def PUSH(dog,info):
>          db.dog[dog].update_record(info=info)
>          return dict()
>      return locals()
>
> My question is very simple: how should my HTTP POST request be
> formatted for it to work and properly insert dog data into the db,
> when using XML? How should the XML in the request body be like?
>
> Thanks in advance.

Reply via email to