1from typing import Optional
2
3from fastapi import Depends, FastAPI
4
5app = FastAPI()
6
7
8fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
9
10
11class CommonQueryParams:
12    def __init__(self, q: Optional[str] = None, skip: int = 0, limit: int = 100):
13        self.q = q
14        self.skip = skip
15        self.limit = limit
16
17
18@app.get("/items/")
19async def read_items(commons=Depends(CommonQueryParams)):
20    response = {}
21    if commons.q:
22        response.update({"q": commons.q})
23    items = fake_items_db[commons.skip : commons.skip + commons.limit]
24    response.update({"items": items})
25    return response
26