一个有意思的Web API框架:apistar

Github地址:https://github.com/encode/apistar

Install API Star:

$ pip3 install apistar

Create a new project in app.py:

from apistar import App, Route

def welcome(name=None):
    if name is None:
        return {'message': 'Welcome to API Star!'}
    return {'message': 'Welcome to API Star, %s!' % name}

routes = [
    Route('/', method='GET', handler=welcome),
]

app = App(routes=routes)

if __name__ == '__main__':
    app.serve('0.0.0.0', 5000, debug=True)

Run app.py

(py3) [root@localhost star]# python app.py
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 684-460-626

Open http://localhost:5000/docs/ in your browser: