繁体   English   中英

如何从 minos RestRequest 访问 aiohttp 的请求

[英]How can I access the aiohttp's Request from a minos RestRequest

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. 我怎样才能做到这一点?

我当前的代码如下所示:

from minos.networks import RestRequest, RestResponse, enroute


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

minos.networks.RestRequest提供raw_request属性,它可以访问内部aiohttp.web.Request实例,以便您可以访问其任何方法或属性

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!)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM