Catching all routes in Aiohttp

How can I catch absolutely all the paths from the received request? I am using the following code, however it does not work.

routes = web.RouteTableDef()

@routes.get(path='/{key}')
async def _(request):
    print(request)
    await self.processing_request(request=request, post=False)

@routes.post(path='/{key}')
async def _(request):
    await self.processing_request(request=request, post=True)

Solution 1:

The default regex for variable paths is [^{}/]+, i.e. it will not match forward slashes. You can specify a custom regex in the path string using {variablename:regex} syntax:

@routes.get(path="/{key:.+}")
async def _(request):
    ...

From the documentation:

A variable part is specified in the form {identifier}, where the identifier can be used later in a request handler to access the matched value for that part. This is done by looking up the identifier in the Request.match_info mapping ...

By default, each part matches the regular expression [^{}/]+.

You can also specify a custom regex in the form {identifier:regex}:

(disclaimer: I have not tested)