So you want to transform /getOrders?account=X&type=Y into something like /orders/account/type using Cherrypy.
I would try the approach used in http://cherrypy.readthedocs.org/en/latest/tutorial/REST.html as mentioned by @Tomasz Blachowicz, with some modifications.
Remember that you can handle something like /order/account/type with
@cherrypy.expose
def order(account=None, type=None):
print account, type
class Root(object):
pass
root = Root()
root.orders = orders
cherrypy.quickstart(root, '/')
So if you take the example given in http://cherrypy.readthedocs.org/en/latest/tutorial/REST.html, you can modify it to handle that type of URL.
class Orders(object):
exposed = True
def __init__(self):
pass
def GET(self, account=None, type=None):
#return the order list for this account type
return getOrders(account, type)
def PUT(self, account=None, type=None, orders=None):
#Set the orders associated with account or something
setOrders(account, type, orders)
class Root(object):
pass
root = Root()
root.orders = Orders()
conf = {
'global': {
'server.socket_host': '0.0.0.0',
'server.socket_port': 8000,
},
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
},
}
cherrypy.quickstart(root, '/', conf)
Why you would want to set orders using that put method I don't know, but it does give an another example of how to do PUT methods. All you have to do is replace the method used by a request with PUT and it will use the PUT() method of Orders and use a regular GET on Orders and it will use the GET() method. Because a POST() method is not defined, POST can't be used with this example. If you try POST or DELETE you will get "405 Method Not Allowed".
I like this approach because it is easy to see what is going on and, I believe, it answers your question.