docs_src/query_params_str_validations/tutorial008_an_py310.py
raw| 1 | from typing import Annotated |
| 2 | |
| 3 | from fastapi import FastAPI, Query |
| 4 | |
| 5 | app = FastAPI() |
| 6 | |
| 7 | |
| 8 | @app.get("/items/") |
| 9 | async def read_items( |
| 10 | q: Annotated[ |
| 11 | str | None, |
| 12 | Query( |
| 13 | title="Query string", |
| 14 | description="Query string for the items to search in the database that have a good match", |
| 15 | min_length=3, |
| 16 | ), |
| 17 | ] = None, |
| 18 | ): |
| 19 | results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} |
| 20 | if q: |
| 21 | results.update({"q": q}) |
| 22 | return results |