views:

180

answers:

1

I need to configure a RESTful style URL that support the following URL scheme:

  • /parent/
  • /parent/1
  • /parent/1/children
  • /parent/1/chidren/1

I want to use the MethodDispatcher so that each of the above can have GET/POST/PUT/DELETE functions. I have it working for the first and second, but can't figure out how to configure the dispatcher for the children portion. I have the book, but it barely covers this and I can't find any sample online.

Here is how I have the MethodDispatcher configured currently.

root = Root()
conf = {'/' : {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}}    

cherrypy.quickstart(root, '/parent', config=conf)

Any help would be appreciated.

+2  A: 

http://tools.cherrypy.org/wiki/RestfulDispatch might be what you're looking for.

In CherryPy 3.2 (just now coming out of beta), there will be a new _cp_dispatch method you can use in your object tree to do the same thing, or even alter traversal as it happens, somewhat along the lines of Quixote's _q_lookup and _q_resolve. See http://www.cherrypy.org/wiki/WhatsNewIn32#DynamicDispatchbyControllers

fumanchu
Perfect. This is exactly what I need, but I couldn't find it because I was focused on MethodDispatcher in my Googling. Thanks.