Coverage for docs_src/dependencies/tutorial004_py310.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from fastapi import Depends, FastAPI 1fghij
3app = FastAPI() 1fghij
6fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] 1fghij
9class CommonQueryParams: 1fghij
10 def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100): 1fghij
11 self.q = q 1abcde
12 self.skip = skip 1abcde
13 self.limit = limit 1abcde
16@app.get("/items/") 1fghij
17async def read_items(commons: CommonQueryParams = Depends()): 1fghij
18 response = {} 1abcde
19 if commons.q: 1abcde
20 response.update({"q": commons.q}) 1abcde
21 items = fake_items_db[commons.skip : commons.skip + commons.limit] 1abcde
22 response.update({"items": items}) 1abcde
23 return response 1abcde