[QUESTION] How to pass list in query parameters?
See original GitHub issueDescription
I need to support several query parameters with same name in GET route. Typical request looks like this: http://localhost/item?num=1&num=2
I configured a route
@app.get("/item", content_type=UJSONResponse)
async def get_part(num: list):
found = False
for i in num:
if i in some_data:
found = True
break
return {"found": found}
The idea is, that I can pass several numbers to check, if they exist in some_data. In my opinion, it is not a good idea to get numbers from body here, because it is a simple GET request, but in current version application expects argument “num” in body, so on my request (written above) I receive a response
{"detail":[{"loc":["body","num"],"msg":"field required","type":"value_error.missing"}]}
As I know, it is not restricted to pass several query parameters with the same name in an HTTP request by any specifications, so I would like to ask, is it possible to configure a route in FastAPI, which will be able to parse several query parameters with the same name?
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (8 by maintainers)
It is supported (and tested), but not documented yet, but you can just use standard Python types (a
List
) 😃Is it possible to do:
http://localhost/item?num=1,2,3,4,5,6
instead of:
http://localhost/item?num=1&num=2&num=3&num=4&num=5&num=6
?