Source

pyrest / pyrest / integration / cherry.py

Full commit
import cherrypy
from pyrest.pyrest import get_handlers, requesthandler
from pyrest.examples import hg

class PyRest(object):
    def __init__(self):
        self._handlers = get_handlers(hg)
        
    def index(self):
        return "Awesome API..."

    def api(self, resource, *pathargs, **kwargs):
        method = cherrypy.request.method.lower()
        response = requesthandler(self._handlers, method, resource, *pathargs, **kwargs)
        cherrypy.response.status = response.status
        return response.content
    index.exposed = True
    api.exposed = True

CONF = {
    'global': {
        'server.socket_host': '0.0.0.0',
        'server.socket_port': 8888,
    }
}


if __name__ == '__main__':
    ROOT = PyRest()
    cherrypy.quickstart(ROOT, '/', CONF)
    
def application(environ, start_response):
  cherrypy.tree.mount(PyRest(), '/', None)
  return cherrypy.tree(environ, start_response)