router.counter = 0 router.__name__ = "First router" router.fake_datebase = {} start = date.today() objects = { 1: {"field_a": "a", "field_b": "b"}, 2: {"field_a": "a", "field_b": "b"}, 3: {"field_a": "a", "field_b": "b"}, # .... # } router.secret_key = "very constatn and random secret, best 64+ characters" router.access_tokens = [] security = HTTPBasic() class HelloResp(BaseModel): msg: str class Person(BaseModel): name: str surname: str class RegisteredPerson(BaseModel): id: int
from hashlib import sha256 from typing import List from fastapi import Request, Query, APIRouter, Response, Cookie, HTTPException from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates lecture2 = APIRouter() templates = Jinja2Templates(directory='templates') lecture2.secret_key = "secret should be long because it is more secjurne" lecture2.access_tokens = list() # http://127.0.0.1:8000/lec2/request_query_string_discovery/?asd=2&aac=abc @lecture2.get("/request_query_string_discovery/") def get_all_query_params(request: Request): qp = request.query_params print(f"{qp = }") return qp # http://127.0.0.1:8000/lec2/request_query_string_discovery2/?u=1&q=2&u=3&q=4 @lecture2.get("/request_query_string_discovery2/") def get_all_query_params2(u: str = Query("default"), q: List[int] = Query(None)): query_items = {"q": q, "u": u} return query_items