Re: [web2py] REST the web2py way - RFC

2011-03-13 Thread contatogilson...@gmail.com
Would not it be better to do this?

@request.get()
<@request.post()>
<@request.put()>
<@request.delete()>
def api():
(...)
return dict(...)

_
*Gilson Filho*
*Web Developer
http://gilsondev.com*


[web2py] REST the web2py way - RFC

2011-03-12 Thread Massimo Di Pierro
This is the result of a brainstorming session at PyCon with web2py
users Jay, Kevin, Shawn and Nathan.

We could use some help with testing and more importantly usability.

Please check out trunk and put this in your code


@request.restful()
def api():
def GET(*args,**vars):
parser = db.parse_as_rest("all",args,vars)
if parser.status == 200:
return dict(content=parser.response)
else:
raise HTTP(parser.status,parser.error)
return locals()

then visit

//default/api/list.json

you will get a list of patterns for example /table-by-field/
{table.field}/:field
where table and field will be some of your tables and fields. Now try
a pattern, for example the one mentioned

//default/api/table-by-field//


You can create your own patterns. They can be complex and involve
multiple tables. There is a more complex example in db.parse_as_rest
docstring.

What do you think? Is this general enough?

Massimo