forked from bybatkhuu/module-fastapi-logging
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouter.py
More file actions
46 lines (28 loc) · 845 Bytes
/
router.py
File metadata and controls
46 lines (28 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from pydantic import validate_call
from fastapi import FastAPI, APIRouter, HTTPException
from fastapi.responses import RedirectResponse
router = APIRouter()
@router.get("/")
def root():
return {"Hello": "World"}
@router.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
@router.get("/continue", status_code=100)
def get_continue():
return {}
@router.get("/redirect")
def redirect():
return RedirectResponse("/")
@router.get("/error")
def error():
raise HTTPException(status_code=500)
@validate_call(config={"arbitrary_types_allowed": True})
def add_routers(app: FastAPI) -> None:
"""Add routers to FastAPI app.
Args:
app (FastAPI): FastAPI app instance.
"""
app.include_router(router)
return
__all__ = ["add_routers"]