Reputation: 513
This is my first outing with CherryPy so forgive any stupidity.
I'm trying to write a RESTful API that in part deals with adding/removing people. I want to be able to GET/PUT/DELETE example.com/people/.
The dispatcher seems to be behaving totally differently for the index method vs a defined function:
class people:
"""This is the class for CherryPy that deals with CRUD on people"""
@cherrypy.expose
def index(self, name):
return name
@cherrypy.expose
def who(self, name):
return name
root = webroot()
root.people = people()
cherrypy.quickstart(root)
If I call example.com/people/tom, I get a 404, if I call example.com/people/who/tom I get 'tom' returned.
Can anyone see what I'm doing wrong? Is there a way I can pass /xxx to index?
Upvotes: 1
Views: 257
Reputation: 1418
Indexes are a bit different when it comes to URL arguments.
The index method has a special role in CherryPy: it handles intermediate URI’s that end in a slash; for example, the URI /orders/items/ might map to root.orders.items.index. The index method can take additional keyword arguments if the request includes querystring or POST params; see Keyword Arguments, next. However, unlike all other page handlers, it cannot take positional arguments
However, the url of example.com/people?name=tom
should work as you expect.
Upvotes: 2