lqs
d20566fe07
Some checks failed
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Issue Manager / issue-manager (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
21 lines
443 B
Python
21 lines
443 B
Python
from fastapi import Cookie, Depends, FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
def query_extractor(q: str | None = None):
|
|
return q
|
|
|
|
|
|
def query_or_cookie_extractor(
|
|
q: str = Depends(query_extractor), last_query: str | None = Cookie(default=None)
|
|
):
|
|
if not q:
|
|
return last_query
|
|
return q
|
|
|
|
|
|
@app.get("/items/")
|
|
async def read_query(query_or_default: str = Depends(query_or_cookie_extractor)):
|
|
return {"q_or_cookie": query_or_default}
|