Finite URLs: types and data
The order links above the post list go to /list/newest/ and /list/oldest/. The
route declares its parameter with a Literal, so OpenAPI already lists every value:
@app.get("/list/{order}/", response_class=HTMLResponse)
def post_list(request: Request, order: Literal["newest", "oldest"]): ...
HTMX fetches one of those two URLs and swaps the list in place. Each is a frozen file, so the swap works on a static host too.
A post's slug is different. Its type is str, which has no end, and only the posts
themselves know which slugs exist. So the route lists them with @freeze_values:
def post_slugs():
return [{"slug": slug} for slug in app.state.posts]
@app.get("/posts/{slug}/", response_class=HTMLResponse)
@freeze_values(post_slugs)
def post(request: Request, slug: str): ...
The posts are loaded in the app's lifespan, like a database connection, and
fastapi-freeze calls post_slugs after startup, so the data is there.
State lives in the path, not the query string. A static host ignores ?order=oldest,
so a query parameter can never select a different file.