Skip to main content

Pretty tornado wrapper for making lightweight REST API services

Project description

cleanapi

Pretty tornado wrapper for making lightweight REST API services


Installation:

pip install cleanapi

Example:

Project folders structure:

.
├── handlers
│   └── example_handler.py
├── server_example.py
├── ssl
│   ├── ca.csr
│   └── ca.key
└── static_html
    └── index.html

server_example.py

from cleanapi import server

if __name__ == '__main__':
    try:
        # protocol = 'https'
        protocol = 'http'

        if protocol == 'https':
            server.start(protocol, 8080, '/', './handlers', './static_html',
                         path_to_ssl='./ssl', ssl_certfile_name='ca.csr', ssl_keyfile_name='ca.key')
        elif protocol == 'http':
            server.start(protocol, 8080, '/', './handlers', './static_html')
        else:
            print(f'Protocol {protocol} is not supported')
    except KeyboardInterrupt:
        print('Server was stopped by user')
        exit()

example_handler.py

Put it to the 'handlers' folder

from cleanapi import BaseHandler

url_tail = '/example.json'


# noinspection PyAbstractClass
class Handler(BaseHandler):
    """
    Test API request handler
    """
    async def get(self):
        self.set_status(200)
        self.write({'status': 'working'})

index.html

Put it to the 'static_html' folder

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Cleanapy demo</title>
  <link rel="icon" href="/favicon.ico" type="image/x-icon" />
 </head>
<body>

<h1>Cleanapy demo page</h1>

<p>Everything OK</p>

</body>
</html>

You also may put 'favicon.ico' file to the 'static_html' folder

Then you can test server responses on http://localhost:8080 and http://localhost:8080/example.json


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cleanapi-0.1.1.tar.gz (15.7 kB view hashes)

Uploaded Source

Built Distribution

cleanapi-0.1.1-py3-none-any.whl (16.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page