Mounting the submodules
All the FastAPI decorators of each sub-application must be mounted in the main.py
component of the top-level application for them to be accessed at runtime. The mount()
function is invoked by the FastAPI decorator object of the top-level application, which adds all FastAPI instances of the sub-applications into the gateway application (main.py
) and maps each with its corresponding URL context. The following script shows how the mounting of the library, student, and faculty subsystems is implemented in the main.py
component of the University ERP top-level system:
from fastapi import FastAPI from student_mgt import student_main from faculty_mgt import faculty_main from library_mgt import library_main app = FastAPI() app.mount("/ch04/student", student_main.student_app) app.mount("/ch04/faculty", faculty_main.faculty_app) app.mount("/ch04/library", library_main.library_app)
With this setup, the mounted /ch04/student
URL will be...