import asyncio from aiohttp import web @asyncio.coroutine def hello(request): return web.Response(body=b"Hello, world") @asyncio.coroutine def variable_handler(request): name = request.match_info.get('name', "Anonymous") text = "Hello, " + name return web.Response(body=text.encode('utf-8')) @asyncio.coroutine def variable_handler_uni(request): "CONTENT-TYPE:text/plain; charset=utf-8" return web.Response( text="Hello, {}".format(request.match_info['name'])) app = web.Application() app.router.add_route('GET', '/{name}', variable_handler) app.router.add_route('GET', '/uni/{name}', variable_handler_uni) loop = asyncio.get_event_loop() f = loop.create_server(app.make_handler(), '0.0.0.0', 8080) srv = loop.run_until_complete(f) print('serving on', srv.sockets[0].getsockname()) try: loop.run_forever() except KeyboardInterrupt: pass