0

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
Chris
  • 18,724
  • 6
  • 46
  • 80
Ivan
  • 7,448
  • 14
  • 69
  • 134
  • You may also want to have a look [here](https://stackoverflow.com/a/71039241/17865804) and [here](https://stackoverflow.com/a/70840850/17865804), as well as [here](https://stackoverflow.com/a/73982479/17865804), [here](https://stackoverflow.com/a/70845425/17865804) and [here](https://stackoverflow.com/a/75998823/17865804) – Chris May 12 '23 at 17:01

1 Answers1

0

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

M.O.
  • 1,712
  • 1
  • 6
  • 18
  • 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? – Ivan May 12 '23 at 14:51
  • `def corr(symbols: List[str], sample: str)` – MatsLindh May 12 '23 at 18:11
  • 1
    @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. – Chris May 12 '23 at 19:08