PyPi Version

CleanAPI

Pretty tornado wrapper for making lightweight REST API services


Installation:

pip install cleanapi

Example:

Project folders structure:

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

server_example.py

from cleanapi import server

if __name__ == '__main__':
    # uses http protocol
    server.start('http', 8080, '/', './handlers', './static_html')

    # # uses https protocol
    # server.start('https', 8443, '/', './handlers', './static_html',
    #              path_to_ssl='./ssl', ssl_certfile_name='ca.csr', ssl_keyfile_name='ca.key')

simple_handler.py

from cleanapi.server 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

<div class="highlight highlight-text-html-basic position-relative" data-snippet-clipboard-copy-content="

Cleanapy demo

Cleanapy demo page

Everything OK

“>

<!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>