I send the list as param:
import requests
def test():
params = {"test_param": [1, 2, 3]}
response = requests.get("http://localhost:8000/test", params=params, timeout=20)
response_data = response.json()
print(response_data)
and handle everything with FastAPI
#!/usr/bin/env python3
from fastapi import FastAPI
from fastapi.responses import JSONResponse
import uvicorn
app = FastAPI()
@app.get("/test")
def test(test_param: list):
return JSONResponse(content={"message": test})
if __name__ == "__main__":
uvicorn.run("minimal:app", host="0.0.0.0", port=8000,
workers=2) # Use the on_starting event)
and I get the error "GET /test?test_param=1&test_param=2&test_param=3 HTTP/1.1" 422 Unprocessable Entity
, but I thought that listing the parameter multiple times is the desired way of how FastAPI wants to receive lists...
My error might be that I am not using typing as described here, but imho that shouldn't influence the result as typing is ignored by python anyway: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#query-parameter-list-multiple-values