Path parameter with List
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
@app.get(
V4L2_ROUTE + "controls/{ctrl_list}",
response_model=List[ControlValue],
tags=[Tags.controls],
)
def get_controls(
ctrl_list: List[str],
params: CommonParams = Depends(),
) -> JSONResponse:
"""Get v4l2 controls"""
return Camera.get_controls(ctrl_list, params.dev)
Description
When trying to declare a route with a Path parameter which is a List I get the following error: AssertionError: Path params must be of one of the supported types
But from what I can see it should be possible to have Lists in the Path: https://stackoverflow.com/questions/2602043/rest-api-best-practice-how-to-accept-list-of-parameter-values-as-input
Fx: http://our.api.com/Product/101404,7267261
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.85.0
Python Version
Python 3.10.5
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Store @PathParam values from REST call in a list or array
Is it possible to store them in an array or list, so I do not list dozens of @PathParams and parameters, to avoid...
Read more >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 >What are Path Parameters? Technical topics explained simply
Path parameters are request parameters attached to a URL that point to a specific REST API resource. The path parameter is separated from ......
Read more >Path Parameters - FastAPI
You can declare path "parameters" or "variables" with the same syntax used by Python format strings: from fastapi import FastAPI app = FastAPI() ......
Read more >@PathParam | RESTful Java with JAX-RS 2.0 (Second Edition)
@PathParam allows you to inject the value of named URI path parameters that were defined in @Path ... In these cases, you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A
Path
param is always aint
or astr
. However, you could simply do the conversion yourself. The below example shows how to deal with a list of values like ‘int,int,int’ etc. Using pydantic, I will also perform basic validation, yay!This will take the
str
and will split it (resulting in alist
), and construct a Pydantic model with its parts (thus performing validation). The above will run as is.Ah, get it, great!