| Status: | From Trac |
|---|
Restfull Path
The aim is to make use of URLs like http://mysite/id/verb, where id is a database identifier and verb is an action to take, like show. A few examples:
class content:
@turbogears.expose()
def default(self, *vpath, **params):
if len(vpath) == 1:
identifier = vpath[0]
action = self.show
elif len(vpath) == 2:
identifier, verb = vpath
verb = verb.replace('.', '_')
action = getattr(self, verb, None)
if not action:
raise cherrypy.NotFound
if not action.exposed:
raise cherrypy.NotFound
else:
raise cherrypy.NotFound
items = self.query(identifier)
if items.count() == 0:
raise cherrypy.NotFound
else:
return action(items[0], **params)Then integration can succeed as follows
class Root(controllers.RootController, content):
@turbogears.expose(template='myapp.templates.show_thing')
def show(self, thing):
return dict(text=thing.text)
@turbogears.expose(template='myapp.templates.edit_form')
def edit(self, thing):
return dict(text=thing.text)
def query(self, name):
return model.something.byName(name=name)See http://www.xfront.com/REST-Web-Services.html for information on why RESTful urls are useful.
| localhost | I think the right spelling is "restful" (with only one l) |
2007-04-11 08:07:45 X | ||