I'm somewhat skeptical about the usefulness of this. I have a couple of legacy apps which have been built like this - the routes tied to the database model - and came to appreciate the level of indirection added by routes. In my experience the direct relation between db objects and resources in the REST sense tends to break down once a project gets bigger. I also think that you get halfway there by using appropriate context factories for the requests. regards, robert
On Thu, Dec 22, 2011 at 4:44 PM, Tarek Ziadé <[email protected]> wrote: > Hey > > Gael's idea on using a class to define all methods for a service, gave me > another idea: add a light CRUD on the top of SQLAlchemy, in Cornice > > I post it here and now because I think it overlaps a little bit Gael's > proposal > > The idea would be to point to Cornice an SQLAlchemy mapping and have it > "published" as a set of RESTful APIs. > > Example (see the __path__ attribute): > > from sqlalchemy.ext.declarative import declarative_base, Column > from sqlalchemy import Integer, String, Text > from cornicedb import DataPublisher > > > _Base = declarative_base() > > > class Application(_Base, DataPublisher): > __tablename__ = 'applications' > __path__ = '/applications' > > id = Column(Integer, primary_key=True) > user = Column(String(256), nullable=False) > collection = Column(String(256), nullable=False) > origin = Column(String(256), nullable=False) > last_modified = Column(Integer, nullable=False) > data = Column(Text) > > > This would generate automatically these REST-ish URIs: > > - GET /applications - get the whole table, with batch options > - POST /applications - adds one or several rows > - DELETE /applications - adds one or several rows > - GET /applications/1 - get the row of id 1 > - PUT /applications/1 - updates the row of id 1 > - DELETE /applications/1 - delete the row of id 1 > - etc.. > > Other features I have in mind: > > - you can override or deactivate any one of these API by adding get() post() > etc, methods to the class > - you can write pre/post hooks, to add authentication etc > - you can define what we already have in cornice (validators, etc) > > One pitfall: have the view and the data controller mixed in one single > class. If we start to have more code atop the data, it could become a mess > > Cheers > Tarek > > -- > Tarek Ziadé | http://ziade.org > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
