I'm making a RESTful WebService using CherryPy 3 but I encounter a problem : I want to be able to answer requests like : /customers/1/products/386 meaning I want all the product with ID 386 of the client with ID 1.
So I try to make it with the CherryPy's MethodDispatcher like this :
class UserController(object):
exposed = True
def __init__(self):
self.product = ProductController()
@log_io
def GET(self, *args):
return "GET Users :" + str(args)
class ProductController(object):
exposed = True
@log_io
def GET(self, *args):
return "GET Product :" + str(args)
But when I request /customers/1/products/386, instead of redirecting me to ProductController.GET with the right parameters, it redirects me to UserController.GET with the parameters 1, "products", 386.
To be redirected to ProductController.GET I have to query /customers/products/386 which is incorrect because I miss the user ID parameter.
I've seen on this presentation : RESTful Web Applications with CherryPy that the path style I want to use seems to be a good choice. But is there an easy way to implement it with Cherry Py ?
I've heard about the _cp_dispatch method of CherryPy 3 but I don't get exactly what it is and how to use it. Does it replace the MethodDispatcher ?