App

class clink.App(conf)[source]

Application brings APIs to HTTP

Parameters:conf (clink.AppConf) –
add_handler(handler_type)[source]

Add handler to application

Parameters:handler_type (class) –
add_prim(*args)[source]
add_ctl(ctl_type)[source]

Add controller to application

Parameters:ctl (class) –
add_ctls(module)[source]

Search controllers in module and add them to application

load()[source]

Creeate instance of all of components, put it to ready state

__call__(wsgi_env, wsgi_send)[source]

Implemention of WSGI. That mean you can call instance of App by WSGI server to make application is available on network.

Parameters:
  • wsgi_env (dict) –
  • wsgi_send (function) –

Example

app.py
from clink import App, AppConf, stamp, mapper, Controller
from wsgiref.simple_server import make_server

conf = AppConf('book-api', 'Hell Corporation', '1st, Hell street')
app = App(conf)


@stamp()
@mapper.path('book')
class BookCtl(Controller):
    @mapper.get('item')
    def get_item(self, req, res):
        res.body = {
            'name': 'How to Die',
            'author': 'Death'
        }


app.add_com(BookCtl)
app.load()


address = 'localhost'
port = 8080
print('Prepare API on http://%s:%i/book/item' % (address, port))
httpd = make_server(address, port, app)
httpd.serve_forever()

Testing

$ python app.py
[1] 5940

$ curl localhost:8080/book/item
{"name": "How to Die", "author": "Death"}

$ kill %1