mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-24 06:39:31 -05:00
* 🔧 Update pre-commit, use ruff format * ⬆️ Upgrade dependencies, use Ruff for formatting * 🔧 Update Ruff config * 🔨 Update lint and format scripts, use Ruff * 🎨 Format internals with Ruff * 🎨 Format docs scripts * 🎨 Format tests * 🎨 Format extra commas in src for docs * 📝 Update docs mentioning `@lru_cache()`, use `@lru_cache` instead to keep consistency with the format * 🎨 Update src for docs, use plain `@lru_cache` * 🎨 Update src for docs format and docs references
25 lines
574 B
Python
25 lines
574 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI, Query
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/items/")
|
|
async def read_items(
|
|
q: Union[str, None] = Query(
|
|
default=None,
|
|
alias="item-query",
|
|
title="Query string",
|
|
description="Query string for the items to search in the database that have a good match",
|
|
min_length=3,
|
|
max_length=50,
|
|
pattern="^fixedquery$",
|
|
deprecated=True,
|
|
),
|
|
):
|
|
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
|
if q:
|
|
results.update({"q": q})
|
|
return results
|