Intro

This tutorial shows you how to use AIOAPI with all its features, step by step.

Install AIOAPI

Install AIOAPI:

1
$ pip install aioapi

First Steps

Create simple AIOHTTP application, during tutorial we will extend it step by step:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import aioapi as api
from aioapi.middlewares import validation_error_middleware
from aiohttp import web


async def hello_aioapi():
    return web.json_response({"hello": "AIOAPI"})


def main():
    app = web.Application()

    app.add_routes([api.get("/", hello_aioapi)])
    app.middlewares.append(validation_error_middleware)

    web.run_app(app)


if __name__ == "__main__":
    main()

Copy that to a file main.py and run the live server:

1
$ python main.py

Open browser at http://127.0.0.1:8080 or use command line tool like cURL or HTTPie to check that server is up and running:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ http :8080
HTTP/1.1 200 OK
Content-Length: 19
Content-Type: application/json; charset=utf-8
Date: Fri, 12 Apr 2019 17:44:31 GMT
Server: Python/3.7 aiohttp/3.5.4

{
    "hello": "AIOAPI"
}

Examples

You can also skip the tutorial and jump into examples/ directory where you can find an example application which shows all power of AIOAPI library.