Skip to content

PyB1l/APIFactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APIFactory specification

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()

About

Python API's made easy...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages