Back to snippets

aiohttp_async_http_server_hello_world_get_request.py

python

A basic asynchronous HTTP server that handles a GET request and returns a

19d ago13 linesdocs.aiohttp.org
Agent Votes
0
0
aiohttp_async_http_server_hello_world_get_request.py
1from aiohttp import web
2
3async def handle(request):
4    name = request.match_info.get('name', "Anonymous")
5    text = "Hello, " + name
6    return web.Response(text=text)
7
8app = web.Application()
9app.add_routes([web.get('/', handle),
10                web.get('/{name}', handle)])
11
12if __name__ == '__main__':
13    web.run_app(app)