I’m trying to build a small site with an index etc. and an api that I want in /api.
For example:
class Site(object):
@cherrypy.expose
def index(self):
return "Hello, World!"
@cherrypy.expose
def contact(self):
return "Email us at..."
@cherrypy.expose
def about(self):
return "We are..."
class Api(object):
@cherrypy.expose
def getSomething(self, something):
db.get(something)
@cherrypy.expose
def putSomething(self, something)
So, I’d like to be able to go to mysite.com/contact and mysite.com/Api/putSomething
If I use cherrypy.quickstart(Site()), I’ll only get the pages under Site.
I think there’s a way of mapping the class Api under /Api, but I can’t find it.
Update (13th March, 2017): The original answer below is quite outdated but am leaving it as it is to reflect the original question that was asked.
The official documentation now has a proper guide on how to achieve it.
Original Answer:
Look at the default dispatcher. The entire documentation for Dispatching.
Quoting from the docs:
This link gives even more detail on it with a complete example shown below.