Routes

LongLink projects use standard FastAPI(opens in new tab). Define routes directly on the LongLink application in main.py. Type a route parameter as Context to receive the request-scoped database session, storage filesystem, and signed-in user.

TODO

Usage

main.pypython
from sqlmodel import select
from src.models.items import Item
from longlink import Context, LongLink
app = LongLink()
@app.get("/api/items", response_model=list[Item])
async def list_items(ctx: Context) -> list[Item]:
"""Return catalog items."""
result = await ctx.database.exec(select(Item).order_by("id"))
return result.all()