(Feat): Initial Commit.

This commit is contained in:
2026-01-05 22:11:58 +00:00
commit b9224dd031
21 changed files with 3259 additions and 0 deletions

42
examples/basic_usage.py Normal file
View File

@@ -0,0 +1,42 @@
"""Basic usage example of fastapi-route-loader."""
from fastapi import APIRouter, FastAPI
from fastapi_route_loader import RouterContainer
app = FastAPI(title="Basic Usage Example")
container = RouterContainer()
users_router = APIRouter(prefix="/users", tags=["users"])
@users_router.get("/")
def list_users() -> dict[str, list[str]]:
"""List all users."""
return {"users": ["alice", "bob"]}
@users_router.get("/{user_id}")
def get_user(user_id: int) -> dict[str, int]:
"""Get a specific user."""
return {"user_id": user_id}
posts_router = APIRouter(prefix="/posts", tags=["posts"])
@posts_router.get("/")
def list_posts() -> dict[str, list[str]]:
"""List all posts."""
return {"posts": ["post1", "post2"]}
container.add_router("users", users_router)
container.add_router("posts", posts_router)
container.register_to_app(app)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)