Here I'm creating operation , and I want to pass to it multiple query parameters like
/test?query=1&query=2&query=3
this is my code:
from typing import List
from fastapi import FastAPI, Query, Body
app = FastAPI(debug=True)
@app.get("/test")
def check(query: List[int]):
return query
in docs I should see this param
if I call it should accept GET params
No parameters in docs:

when I try to call it - got an error that body is not supplied:

This works:
from typing import List
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/test")
async def test(query: List[int] = Query(...)) -> List[int]:
return query
All the best :)
Your request might have been mapped to https://fastapi.tiangolo.com/tutorial/body/. Unfortunately I am not sure if your use case is supported at all. Probably by reading request: Request directly? You can try reading Request document in Starlette to figure it out.
Alright https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#query-parameter-list-multiple-values
You can close the issue if it works for you.
This works:
async def test(query: List[int] = Query(...)) -> List[int]:
All the best :)
Yes, it works, but my guess is - either FastAPI should raise some validation error or it should treat default params as Query (like it does for string, int annotations)
I think the error points to missing query in the body of the request. That is what I understood :)
Thanks for the help here everyone! :clap: :bow:
@vitalik you are using a "complex" data type, a list of ints, by default it will try to read it from the body. You have to make it explicit that you want it from a query if you want it to come from the query.
yeah, I would say either it should allow it in get or it should make schema docs for request body
OR it should validate - that user must not declare body param that is not supported by http method (GET)
Most helpful comment
This works:
All the best :)