Modify root endpoint to return API information

- Change root endpoint to return API information in JSON format
- Include links to documentation and available endpoints
- Keep the endpoint in the OpenAPI schema
This commit is contained in:
Automated Action 2025-05-26 11:56:27 +00:00
parent c1c91cc80f
commit 215640c310

23
main.py
View File

@ -27,11 +27,26 @@ app.add_middleware(
# Include API router # Include API router
app.include_router(api_router, prefix=settings.API_V1_STR) app.include_router(api_router, prefix=settings.API_V1_STR)
# Root route to redirect to documentation # Root route to return API information
@app.get("/", include_in_schema=False) @app.get("/", tags=["Root"])
async def root(): async def root():
from fastapi.responses import RedirectResponse return {
return RedirectResponse(url="/docs") "name": settings.PROJECT_NAME,
"version": settings.VERSION,
"description": "Welcome to the E-commerce API",
"docs": "/docs",
"redoc": "/redoc",
"api_prefix": settings.API_V1_STR,
"endpoints": {
"health": "/health",
"auth": f"{settings.API_V1_STR}/auth",
"users": f"{settings.API_V1_STR}/users",
"products": f"{settings.API_V1_STR}/products",
"categories": f"{settings.API_V1_STR}/categories",
"cart": f"{settings.API_V1_STR}/cart",
"orders": f"{settings.API_V1_STR}/orders"
}
}
# Health check endpoint # Health check endpoint
@app.get("/health", tags=["Health"]) @app.get("/health", tags=["Health"])