There is such a feature in aiohttp called Variable Resources. It's possible to implement similar functionality inside a handler registered with a prefix. In my opinion Variable Resources is more suitable solution.
So here is two examples with the same logic:
Handler With Prefix Path
prefix = '/a'
def split_path(path, prefix):
return path[len(prefix) + 1:].split('/')
@mockserver.json_handler(prefix, prefix=True)
async def handle(request):
path_parts = split_path(request.path, prefix)
if not path_parts or len(path_parts) > 2 or path_parts[1] != 'c':
raise web.HTTPNotFound
b = path_parts[0]
response = {'b': b, 'resource': 'c'}
return response
There is such a feature in aiohttp called Variable Resources. It's possible to implement similar functionality inside a handler registered with a prefix. In my opinion Variable Resources is more suitable solution.
So here is two examples with the same logic:
Handler With Prefix Path
Handler With Variable Resource