Search code examples
aiohttp

How can I add an endpoint with address created by id and querystring?


with aiohttp I would like to create a GET endpoint, where in the url is entered the id I need and also a querystring, I would like that retrieve the image in the db document_id and also the format, querystring type


# app/http/routes/v1/variation.py

routes = [
    get(f"/{version}/{path}/download/{{document_id}}/{{type}}", readvariationController.handle)
]

# app/http/routes/v1/__init__.py
from app.http.routes.v1.variation import routes as variation_routes

routes = variation_routes 

# __main__

app = web.Application()

app.add_routes(routes)

I have no problem with other "simpler" endpoints, but I can't get a more complex endpoint to work, what am I doing wrong?

It returns an error 405

EDIT: What I would like to have is this

http://localhost:3099/v1/storage/download/112/?type=mini

Solution

  • Ok solved:

    self.__request: Request = request
    # get document_id
    self.__request.match_info.get("document_id", None)
    
    # and finally get querystring
    self.__request.rel_url.query['type']