Query parameters - Dictionary support?
See original GitHub issueDescription
While am using this feature, I have this requirement where I need a parameter to be a Dictionary(key values list) for ‘GET’ query parameters. Currently the GET operation seem to support only the following parameter types
- String
- Int
- Enum
- List[str] or List[int]
- Kwargs(variable number of args in dictionary form)
Do you have any recommendations?. One suggestion I got is to use POST
instead of GET
and achieve the flexible query. Is that a good idea?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Getting Query Parameters as Dictionary in FastAPI
One of the requirements for my application is to get all the query parameters in a dictionary (there are multiple combinations, ...
Read more >Serialised dictionary in GET query parameters
Dictionaries sent in the query string are usually serialized as "style: form" + "explode: true". See this link for details and examples:.
Read more >Can I use dictionary to add my query parameters in restsharp ...
I have used a Dictionary<string, string> for my query params but I am getting an error. It shows AddQueryParameter takes string name, ...
Read more >passing dictionary in URL not working. I Get a string
request.vars is simply a representation of a URL query string, which is a collection of key=value items, where key and value are both...
Read more >Query Parameters - FastAPI
When you declare other function parameters that are not part of the path parameters, they are automatically interpreted as "query" parameters. from fastapi ......
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
I guess you can use Depends to achieve it:
Looking at starlette documentation today, I found that you can get a dict of query params by using request like this
`from fastapi import FastAPI, Request from pydantic import BaseModel from typing import Optional from datetime import date
app = FastAPI()
class Query(BaseModel): msg: Optional[str] = None page: Optional[int] = None only_one: bool when: date
@app.get(‘/’) async def home(req: Request, only_one: bool, when: date, msg: str = None, page: int = None): query = Query(**req.query_params).dict(exclude_unset=True) return query`