如何从 minos 中的 RestRequest 访问 aiohttp 的 Request
How can I access the aiohttp's Request from a RestRequest in minos
我有一个用 @enroute.rest.command
装饰器装饰的处理函数,这样我的函数接收一个 RestRequest
实例,但我想直接访问 aiohttp.web.Request
来直接访问rel_url
属性。我该怎么做?
我当前的代码如下:
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!)
我有一个用 @enroute.rest.command
装饰器装饰的处理函数,这样我的函数接收一个 RestRequest
实例,但我想直接访问 aiohttp.web.Request
来直接访问rel_url
属性。我该怎么做?
我当前的代码如下:
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!)