Debian Codegraph @

docs_src/dependencies/tutorial011_py310.py

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