Quickstart

Installation

# python3 is use as interpreter for python language
# curl use to test api
$ apt-get install python3 wget curl

# pip is python package manager
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py

# install clink through pip
$ pip install clink

Writting

app.py
# STEP 1: get clink library
from clink import stamp, mapper, App, AppConf, Controller


# STEP 2: get an WSGI server
from wsgiref.simple_server import make_server


# STEP 3: create application
conf = AppConf('book-api')
app = App(conf)


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


# STEP 5: add controller to application
app.add_ctl(BookCtl)


# STEP 6: load components
app.load()


# STEP 7: serve application on WSGI server
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 &> /dev/null &
[1] 10297

$ curl localhost:8080/book/item
{"name": "Linux Programming Interface", "author": "Michael Kerrisk"}

$ kill %1