Search code examples
pythonrestpython-3.xaiohttp

aiohttp: how-to retrieve the data (body) in aiohttp server from requests.get


Could you please advise on the following?

On the localhost:8900 there is aiohttp server running

When I do a request like (using the python2 module requests) from python

requests.get("http://127.0.01:8900/api/bgp/show-route",
             data={'topo':"switzerland",
                   'pop':"zrh",
                   'prefix':"1.1.1.1/32"})

And there is a route defined in the aiohttp server

app.router.add_route("GET", "/api/bgp/show-route", api_bgp_show_route)

which is being handled like

def api_bgp_show_route(request):
    pass

The question is: how do I retrieve on server-side the data part of the request? meaning {'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"}


Solution

  • ahh the data part is accessed like that

    await request.json()
    

    You can find this in official aiohttp docs