Skip to content
Discussion options

You must be logged in to vote

Since FastAPI 0.115.0 you can officially use Pydantic models to declare Query parameters:

from fastapi import FastAPI, Query
from pydantic import BaseModel
from typing import Optional, List

app = FastAPI()


class SortModel(BaseModel):
    field: Optional[str]
    directions: List[str]


@app.get("/pydanticmodel")
def get_sort(criteria: SortModel = Query()):
    pass  # my code for handling this route.....

Docs: https://fastapi.tiangolo.com/tutorial/query-param-models/

Replies: 9 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
7 participants
Converted from issue

This discussion was converted from issue #2046 on February 28, 2023 18:43.