]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add Frontend instructions to Agent Library Skill (#15805)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 20 Jun 2026 00:59:14 +0000 (02:59 +0200)
committerGitHub <noreply@github.com>
Sat, 20 Jun 2026 00:59:14 +0000 (00:59 +0000)
fastapi/.agents/skills/fastapi/SKILL.md

index d5f32fa3c471314906128c2cafac69b1c9fcc828..f2ecd9eecb2d6693361675ee6ff9e752da546e06 100644 (file)
@@ -288,6 +288,32 @@ There could be exceptions, but try to follow this convention.
 
 Apply shared dependencies at the router level via `dependencies=[Depends(...)]`.
 
+## Serve Frontend Apps
+
+Use `app.frontend()` to serve a built static frontend app, for example a directory generated by Vite, Astro, Angular, Svelte, Vue, or a similar tool.
+
+```python
+from fastapi import FastAPI
+
+app = FastAPI()
+
+app.frontend("/", directory="dist")
+```
+
+Use `router.frontend()` when the frontend belongs to an `APIRouter`; normal router prefix behavior applies when the router is included.
+
+```python
+from fastapi import APIRouter, FastAPI
+
+app = FastAPI()
+router = APIRouter(prefix="/admin")
+
+router.frontend("/", directory="admin-dist")
+app.include_router(router)
+```
+
+`app.frontend()` and `router.frontend()` are low-priority routes: regular API routes are matched first, then frontend files and client-side routing fallbacks. Use this for single-page apps and built frontend assets instead of mounting `StaticFiles` manually.
+
 ## Dependency Injection
 
 See [the dependency injection reference](references/dependencies.md) for detailed patterns including `yield` with `scope`, and class dependencies.