Hi all,
According to what you told me a few weeks ago, Alessandro, I'm about to
inspire from the following documentation for implementing a REST api :
http://turbogears.readthedocs.org/en/latest/cookbook/Crud/restapi.html
My question is: I'd like to define list of attributes (and potentially
renaming of attribute) to be exposed through my API. They are not fixed
for a given model, for example :
- in case of a select filler, I want User as { "user_id" : 4, "name":
"Jean Dujardin" }
- in case of showing user list I want User as { "user_id" : 4, "name":
"Jean Dujardin", "email" : "[email protected]", "status":
"active" } etc, etc.
I also may need to rename some attributes like display_name to name.
There is a really easy way to do this using symfony2/php using @expose
annotations. I was asking myself if there is something similar in
turbogears ?
For example, my User Class would be :
class User(object):
@expose(["users", "user", "user_select_filler"])
user_id = Column(...)
@expose(["users", "user", "user_select_filler"])
display_name = Column(...)
@expose(["users", "user"])
email = Column(...)
and in my controller :
@exposeJson('user_select_filler')
def get_select_filler(self):
return DBSession.query(User).all()
and this would automatically expose a list of user with given properties
only : { user_id, display_name }
Something like this is possible ?
On 01/04/2014 14:49, Damien Accorsi wrote:
Thanks, Alessandro. This is what I was looking for.
Damien
Le 01/04/2014 14:39, Alessandro Molina a écrit :
Far from being perfect but I use
https://pypi.python.org/pypi/sphinxcontrib-jsoncall which
autogenerates doc
for all json controllers. Just remember to skip /admin
Il 01/apr/2014 14:27 "Damien Accorsi" <[email protected]> ha
scritto:
Le 01/04/2014 02:09, Craig Small a écrit :
On Fri, Mar 28, 2014 at 05:22:10PM +0100, [email protected]
wrote:
My question is: is there a simple way to implement a REST/Json api
with
TG2 (with data validation) ? If not, what framework would you
recommend to
do so ? I'm looking for a full-stack framework with features like
user
rights management (like TG2 do).
Isn't that what the backend of things like jqgrid does already?
ie it calls http://server/blah/thing.json and you get all the data
nicely JSON formatted for the thing model.
Permissions and all the other TG goodies don't care what the output
format is for this request, so they just work.
- Craig
Alessandro pointed me to this resource : http://turbogears.readthedocs.
org/en/latest/cookbook/Crud/restapi.html So... building rest/json is
ok.
What about api auto-generated documentation?
Damien
--
You received this message because you are subscribed to the Google
Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it,
send an
email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.