4

I have an endpoint like this:

@app.get("/Corr")
async def Corr(symbols : list, sample : str) -> List[CorrItem]:

I would like to call it with a list of symbols like this:

http://endpoint.com/Corr?symbols=[GOOG, MSFT]&sample=M

I am getting a runtime error:

HTTP/1.1" 422 Unprocessable Entity
1
  • You may also want to have a look here and here, as well as here, here and here Commented May 12, 2023 at 17:01

1 Answer 1

2

The way to send a list in an HTTP request,* as described in the FastAPI documentation is to send the same query parameter several times:

http://endpoint.com/Corr?symbols=GOOG&symbols=MSFT&sample=M

* There are other ways used in HTTP requests, but this is the one accepted by FastAPI

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. That got me farther. However with the signature of def Corr as given, I can't call it at runtime. Can you give an example of what the signature of the function looks like?
def corr(symbols: List[str], sample: str)
@MatsLindh You would need to define the query parameter (i.e., symbols) explicitly with Query; otherwise, it would be interpreted as a request body. Please have a look at the link provided above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.