Debian Codegraph @

docs_src/dependencies/tutorial011_an_py310.py

raw
1 from typing import Annotated
2
3 from fastapi import Depends, FastAPI
4
5 app = FastAPI()
6
7
8 class FixedContentQueryChecker:
9 def __init__(self, fixed_content: str):
10 self.fixed_content = fixed_content
11
12 def __call__(self, q: str = ""):
13 if q:
14 return self.fixed_content in q
15 return False
16
17
18 checker = FixedContentQueryChecker("bar")
19
20
21 @app.get("/query-checker/")
22 async def read_query_check(fixed_content_included: Annotated[bool, Depends(checker)]):
23 return {"fixed_content_in_query": fixed_content_included}