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:
parent
c1c91cc80f
commit
215640c310
23
main.py
23
main.py
@ -27,11 +27,26 @@ app.add_middleware(
|
||||
# Include API router
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
# Root route to redirect to documentation
|
||||
@app.get("/", include_in_schema=False)
|
||||
# Root route to return API information
|
||||
@app.get("/", tags=["Root"])
|
||||
async def root():
|
||||
from fastapi.responses import RedirectResponse
|
||||
return RedirectResponse(url="/docs")
|
||||
return {
|
||||
"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
|
||||
@app.get("/health", tags=["Health"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user