Skip to content

Commit

Permalink
refactor: api route configuration REFS #59
Browse files Browse the repository at this point in the history
this decouples the app specific api configuration from the template fast api
app configuration, post this the template can progress without having to
touch app specific routes
  • Loading branch information
devraj committed Mar 6, 2023
1 parent 2d03b6f commit 308515b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/labs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from fastapi.responses import JSONResponse
from fastapi.routing import APIRoute

from .routers import router_auth, router_ext, router_users
from .routers import router_root

api_description = """
This project provides a reference Python API built using FastAPI, the
Expand Down Expand Up @@ -56,10 +56,7 @@
)

# Additional routers of the application described in the routers package
app.include_router(router_auth)
app.include_router(router_ext, prefix="/ext")
app.include_router(router_users, prefix="/users")

app.include_router(router_root)

@app.get("/")
async def root(request: Request):
Expand Down
20 changes: 19 additions & 1 deletion src/labs/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
"""

from fastapi import APIRouter

from .auth import router as router_auth
from .ext import router as router_ext
from .users import router as router_users
from .users import router as router_users

# Mount all routers at the top level
# this is what the FastAPI app will use
router_root = APIRouter()

router_root.include_router(
router_auth,
)
router_root.include_router(
router_ext,
prefix="/ext",
)
router_root.include_router(
router_users,
prefix="/users",
)

0 comments on commit 308515b

Please sign in to comment.