I have the following endpoint in FastAPI:
@router.get("/", response_model=ApiResponseMultiple[MyObject], response_model_exclude_none=True)
async def get_objs(
request: Request,
ids: list
):
"""Get stuffs"""
print(ids)
...
And I cannot get the list to popoulate froma. postman call. I have tried passing the following from postman:
1,2
[1,2]
ids=1&ids=2
ids[]=1&ids[]=2
ids[0]=1&ids[1]=2
Always my print
statement spits out None
.
Even though you are sending the paramter ids
as a list, FastAPI is expecting it as body parameter, and sending body data for GET request is not allowed :)
Modify your code to mark the parameter ids
explicitly as a query parameter.
Here is a sample:
from fastapi import Query
@router.get("/")
async def get_objs(
ids: list = Query(...)
):
"""Get stuffs"""
print(ids)
...