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.

List as query param

See original GitHub issue

Here I’m creating operation , and I want to pass to it multiple query parameters like

/test?query=1&query=2&query=3

this is my code:

from typing import List
from fastapi import FastAPI, Query, Body

app = FastAPI(debug=True)


@app.get("/test")
def check(query: List[int]):
    return query

Expected behavior

in docs I should see this param if I call it should accept GET params

Screenshots

No parameters in docs:

CleanShot 2020-05-13 at 18 14 02

when I try to call it - got an error that body is not supplied:

CleanShot 2020-05-13 at 18 15 50

Environment

  • OS:macOS
  • FastAPI 0.54.1
  • Python 3.7.4

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
MichalMazurekcommented, May 13, 2020

This works:

from typing import List
from fastapi import FastAPI, Query

app = FastAPI()


@app.get("/test")
async def test(query: List[int] = Query(...)) -> List[int]:

    return query

All the best 😃

1reaction
vitalikcommented, May 13, 2020

This works: async def test(query: List[int] = Query(…)) -> List[int]: All the best 😃

Yes, it works, but my guess is - either FastAPI should raise some validation error or it should treat default params as Query (like it does for string, int annotations)

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 >
REST API Best practice: How to accept list of parameter ...
The standard way to pass a list of values as URL parameters is to repeat them: http://our.api.com/Product?id=101404&id=7267261.
Read more >
Query Parameters and String Validations - FastAPI
To declare a query parameter with a type of list , like in the example above, you need to explicitly use Query ,...
Read more >
REST API query parameters for collection resources - IBM
Query parameters for collection resources ; fields, A comma-separated list of property names. This parameter filters the properties that are returned. Property ...
Read more >
Build api URL using list of query params - OutSystems
You cannot directly do what you propose, as the Platform will encode the "filters" parameter, so the = and & will be encoded...
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