Find file
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (61 sloc) 2.04 KB
from apibase import map
from apibase.baseapp import *
from apibase.schema import api_entry, api_param, api_validate, generateSchema
from webob.dec import wsgify
class Test(BaseController):
description="default handler for a controller",
response={'type': 'string',
'doc': ('this is the index')})
def index(self):
return {"result": "this is the index"}
description="an example view method",
'item': api_param('string', True, None, ['me', 'you'], 'path','User to query'),
response={'type': 'string',
'description': ('returns html view')})
def view(self, item):
return {"result": "this is a view [%s]" % item}
description="test success method",
response={'type': 'object',
'description': ('allways a success object')})
def ok(self):
# accessing the session
self.session['value'] = True
return {"result": "success!"}
description="an example exception failure",
response={'type': 'object',
'description': ('throws an exception')})
def fail(self):
raise Exception("FAIL WHALE")
description="A test wsgi api",
title="Test API Docs",
icons={'x16': ''}
class myApp(BaseApplication):
schema = None
def __call__(self, req):
if not self.schema:
generateSchema(self, req)
return super(myApp, self).__call__(req)
with map.submapper(path_prefix='/myapp/v1') as v1:
v1.connect('/', controller=Test)
v1.connect('/view/{item}', controller=Test, action='view')
v1.connect('/ok', controller=Test, action='ok')
v1.connect('/fail', controller=Test, action='fail')
make_app = set_app(map, appKlass=myApp)