| | """ |
| | Main API module. |
| | """ |
| |
|
| | import logging |
| | from contextlib import asynccontextmanager |
| |
|
| | from fastapi import FastAPI, Depends |
| | from fastapi.middleware.cors import CORSMiddleware |
| |
|
| | from api.inference import router as inference_router |
| | from api.requirements import router as requirements_router |
| | from api import auth |
| | from api.schema import SuccessDetail |
| |
|
| |
|
| | @asynccontextmanager |
| | async def lifespan(app: FastAPI): |
| | logger = logging.getLogger("uvicorn") |
| | logger.info(f"Starting up...") |
| | yield |
| | logger.info(f"Shutting down...") |
| |
|
| |
|
| | app = FastAPI( |
| | title="Team 13 API", |
| | lifespan=lifespan, |
| | ) |
| |
|
| | origins = ["*"] |
| | app.add_middleware( |
| | CORSMiddleware, |
| | allow_origins=origins, |
| | allow_credentials=True, |
| | allow_methods=["*"], |
| | allow_headers=["*"], |
| | ) |
| |
|
| |
|
| | @app.get( |
| | "/", |
| | tags=["HOME"], |
| | summary="Home page", |
| | status_code=200, |
| | response_model=SuccessDetail, |
| | ) |
| | async def home(): |
| | """ |
| | Home page. |
| | """ |
| | return {"success": "Welcome to yet another API!"} |
| |
|
| |
|
| | app.include_router( |
| | requirements_router.router, |
| | prefix="/requirements", |
| | tags=["REQUIREMENTS"], |
| | dependencies=[Depends(auth.validate_api_key)], |
| | ) |
| |
|
| | app.include_router( |
| | inference_router.router, |
| | prefix="/inference", |
| | tags=["INFERENCE"], |
| | dependencies=[Depends(auth.validate_api_key)], |
| | ) |
| |
|