Example Final API
from api_factory import API, APIHandler
class MyAPIHandler(APIHandler):
"""Example Api Handler.
"""
cors_enable = True
def get(self, uid=None):
if uid:
if not uid.isdigit():
return self.response_factory.bad_request(errors=['Invalid UID parameter!'])
if int(uid) <= 0:
return self.response_factory.not_found(errors=['Resource with UID {} not found!'.format(uid)])
return self.response_factory.ok(data={'action': 'Retrieve', 'uid': uid})
return self.response_factory.ok({'action': 'List'})
def post(self):
req_data = self.request.json
return self.request_factory.created(data={'action': Created})
api = API()
api.add_route('/resource', MyAPIHandler)
if __name__ == '__main__':
api.run()