pythonmicroservicesaiohttpminos

How can I access the aiohttp's Request from a RestRequest in minos


I have a handling function decorated with the @enroute.rest.command decorator, so that my function receives a RestRequest instance, but I want to directly access the aiohttp.web.Request to directly access to the rel_url attribute. How can I do that?

My current code looks like:

from minos.networks import RestRequest, RestResponse, enroute


@enroute.rest.command("/products/create", "POST")
async def handle_product_create(request: RestRequest) -> RestResponse:
    ...
    return RestResponse("created!)

Solution

  • The minos.networks.RestRequest provides the raw_request attribute, which gives access to the inner aiohttp.web.Request instance, so that you can access any of its methods or attributes

    from aiohttp import web
    from minos.networks import RestRequest, RestResponse, enroute
    
    
    @enroute.rest.command("/products/create", "POST")
    async def handle_product_create(request: RestRequest) -> RestResponse:
        raw_request: web.Request = request.raw_request
        print(raw_request.rel_url)
        ...
        return RestResponse("created!)