question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How could I send an array of list as query parameters via POST method?

See original GitHub issue

I have to send a list or array as parameters with POST method, like this:

@app.post('endpoint')

async def feedback(feed: List[int])

I expect to be able to send parameters of a list of integer, and return the response.

However, in the UI document, the endpoint couldn’t receive request parameters, instead only showing return 0.

I’d looked for request body, and tried to do something like this:

class Item(BaseModel):
  feedback: int

async def feedback(feed: List[Item])

But that returns this: feedback: 0 and I still could not send parameters of a list.

How could I fulfill this task?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tiangolocommented, Dec 19, 2022

Thanks for the help here @hard-coders ! 👏 🙇

Thanks for reporting back and closing the issue @laurence-lin 👍

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I’m checking each one in order.

1reaction
laurence-lincommented, May 11, 2021

Unfortunately, that’s not possible.

But there is two way. One is using JSON body, and the other is that you need to parse a parameter yourself.

The former is a good way and recommended. The latter looks ugly and not a good way.

@app.post("/endpoint")
async def feedback(feed: List[str] = Query(...)):
    feed_list = [int(_) for _ in feed.split(",")]
    return feed_list

When using the latter, it can’t appear your intention in docs. I hope it helps.

I understand, I may have to create an JSON file containing the list of values, and attach in the request body. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring — Passing list and array of values as URL parameters
Let's see how to send a list of query parameters, and receive them in array/arraylist in Spring. Sending via URL: List of values...
Read more >
Pass array as query parameter in Postman - Stack Overflow
I am calling DELETE method to delete a user from list of databases. It is expecting list of database names as array in...
Read more >
Send Array List through Query Parameters on HTTP Request ...
I am sending array list of Query params through HTTP request Array list id's [1234,3442,9489,9498] · <http:request method="GET" doc:name="Request" doc:id=" ...
Read more >
Pass an array as a parameter | Postman Answers
Parse a variable to use as an array; Loop through an array and use the sendRequest method to send a request directly from...
Read more >
Angular - How to pass arrays via Query Parameters
How to pass an array of values via query parameter in Angular. Tagged with angular, angular11, queryparam, queryparameters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found