Add API routing for v1 endpoints and health check functionality
This commit is contained in:
11
app/api/__init__.py
Normal file
11
app/api/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"""API package."""
|
||||||
|
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from app.api import v1
|
||||||
|
|
||||||
|
# Main API router with /api prefix
|
||||||
|
api_router = APIRouter(prefix="/api")
|
||||||
|
|
||||||
|
# Include version routers
|
||||||
|
api_router.include_router(v1.api_router)
|
||||||
11
app/api/v1/__init__.py
Normal file
11
app/api/v1/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"""API v1 package."""
|
||||||
|
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from app.api.v1 import main
|
||||||
|
|
||||||
|
# V1 API router with v1 prefix
|
||||||
|
api_router = APIRouter(prefix="/v1")
|
||||||
|
|
||||||
|
# Include all route modules
|
||||||
|
api_router.include_router(main.router, tags=["main"])
|
||||||
16
app/api/v1/main.py
Normal file
16
app/api/v1/main.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"""Main router for v1 endpoints."""
|
||||||
|
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from app.core.logging import get_logger
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/")
|
||||||
|
def health() -> dict[str, str]:
|
||||||
|
"""Health check endpoint."""
|
||||||
|
logger.info("Health check endpoint accessed")
|
||||||
|
return {"status": "healthy"}
|
||||||
@@ -3,6 +3,7 @@ from contextlib import asynccontextmanager
|
|||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from app.api import api_router
|
||||||
from app.core.database import init_db
|
from app.core.database import init_db
|
||||||
from app.core.logging import get_logger, setup_logging
|
from app.core.logging import get_logger, setup_logging
|
||||||
from app.middleware.logging import LoggingMiddleware
|
from app.middleware.logging import LoggingMiddleware
|
||||||
@@ -29,12 +30,8 @@ def create_app() -> FastAPI:
|
|||||||
|
|
||||||
app.add_middleware(LoggingMiddleware)
|
app.add_middleware(LoggingMiddleware)
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
# Include API routes
|
||||||
|
app.include_router(api_router)
|
||||||
@app.get("/")
|
|
||||||
def health() -> dict[str, str]:
|
|
||||||
logger.info("Health check endpoint accessed")
|
|
||||||
return {"status": "healthy"}
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user