FastUI as Sub-Application
Hi, I have tried to mount FastUI as a sub-application in my FastAPI service. I tried to follow the proposed solution(s) from #134. However, I still haven't found a way to get this up and running.
I am using the latest release 0.6.0
Can you share a MRE and tell us exactly what went wrong?
Can you share a MRE and tell us exactly what went wrong?
Sure. I tried implementing it as a subapplication with a base route "ui/".
fastui_app = FastAPI()
@fastui_app.get("/api/", response_model=FastUI, response_model_exclude_none=True)
def users_table() -> list[AnyComponent]:
return [
c.Page(
components=[
c.Heading(text='FastUI-Test', level=2)
]
)
]
@fastui_app.get('/{path:path}')
async def html_landing() -> HTMLResponse:
return HTMLResponse(prebuilt_html(title='FastUI Demo'))
app_configuration: ApplicationConfiguration = _build_application_configuration()
app = FastAPI(**app_configuration.model_dump(), lifespan=application_lifespan)
app.mount("/ui", fastui_app)
I’ve had success with creating a router for the FastUI /ui endpoints, rather than an app.
from fastapi import APIRouter
from fastui import FastUI
router = APIRouter()
@router.get("/api/", response_model=FastUI)
async def home():
…
then, in your main app, include the ui router.
from fastapi import FastAPI
from .ui.router import router as ui_router
app = FastAPI()
app.include_router(ui_router, prefix='/ui')
@jimkring I also tried it. However, I am always receiving a Page not found error.
Can you please share the full example? How do you configure the html_landing function? Is it part of the ui_router or?
I'll add an example to @hasansezertasan/fastui-tutorials and address this issue when I get the chance.
I'll add an example to @hasansezertasan/fastui-tutorials and address this issue when I get the chance.
Hey 👋, I've finished the example, could you please check it out?
Here is the related pr: hasansezertasan/fastui-tutorials#17
Nice thank you. It is working.
Nice thank you. It is working.
Happy to help 🙏.