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.

2
  • 1
    What's your question? And: What do you have up to now? Commented Aug 14, 2022 at 17:12
  • My question is how do I take an arbitrary amount of parameters in the query Commented Aug 14, 2022 at 17:26

1 Answer 1

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
    ...
Sign up to request clarification or add additional context in comments.

3 Comments

With the '...' do you mean other parameters? otherwise it's considered an error. Also in this way, Swagger can't add any documentation.
Yes, I was meaning your other parameters (path parameters, session etc)
Sorry, but if the query parameters aren't defined a priori, what Swagger UI should show ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.