1

I have a requirement to send dynamic query parameters to REST web service GET method [as shown below].

host:port/app?field1=value1&&field2=value2&....

The consumer can send parameters up to fieldn and valuen. Each field maps to the value.

With this type of requirement, I can't code a finite set of QueryParams on the server side method.

I'm using python and fastapi

Thanks.

Chris
  • 18,724
  • 6
  • 46
  • 80

1 Answers1

1

The idea to pass an arbitrary number of query parameters to the endpoint is to use the Request class provided by FastAPI. It gives a dict with all the query parameters you passed to the endpoint. Write your endpoint like the following:

@app.get("/app")
def read(..., request: Request):
    query_parameters_dict = request.query_params
    ...
joaopfg
  • 1,227
  • 2
  • 9
  • 18