-
|
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 queryExpected behaviorin docs I should see this param ScreenshotsNo parameters in docs: when I try to call it - got an error that body is not supplied: Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
|
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 queryAll the best :) |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
You can close the issue if it works for you. |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
|
I think the error points to missing |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here everyone! 👏 🙇 @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. |
Beta Was this translation helpful? Give feedback.
-
|
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) |
Beta Was this translation helpful? Give feedback.
-
|
Actually, FastAPI supports reading bodies from
|
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.


Actually, FastAPI supports reading bodies from
GETrequests. It's not standard, it's not part of the specs, but it's allowed for compatibility, for example with ElasitcSearch.