blog post/code sample: automatic routing for RESTful webpy controllers

60 views
Skip to first unread message

Ken Woodruff

unread,
Jul 2, 2012, 8:33:30 PM7/2/12
to we...@googlegroups.com
Just wasted better part of a day coming up with (and then blogging about) a more refined approach for automatically routing RESTful controllers and thought I'd share.  Note that I'm no Python expert and I'm a total web.py n00b so can't vouch for whether this is well done nor if it's particularly original, but hopefully someone here can benefit from it.  Comments/corrections/enhancements/prior art references welcome on the blog (not sure if I'll be able to actively participate in discussion here).

The TL;DR is with the autoroute() function given in the post you can write a simple restful controller 

class FooBarController():
  __metaclass__ = autoroute()
  def GET(self, foo_id, bar_name):
     # ....

and it will automagically be assigned a URL like

/foo/bar/([0-9]+)/([A-Z])+/?

--Ken
Reply all
Reply to author
Forward
0 new messages