Responses
Controller actions may return several shapes. The HTTP kernel normalizes them into ASGI responses.
Return values
Section titled “Return values”| Return | Result |
|---|---|
dict / list |
JSON (application/json) |
str |
Plain text |
bytes |
Raw body |
None |
204 (or the status you pass to helpers) |
| A response object | Used as-is |
Prefer explicit helpers when the intent matters:
from almasix.http import html, json, redirectfrom almasix.prism import view
async def index(self): return view("welcome", {"name": "Ada"})
async def data(self): return json({"ok": True})
async def legacy_markup(self): return html("<h1>Hi</h1>")
async def leave(self): return redirect("/progress")Web vs API polarity
Section titled “Web vs API polarity”- Web routes (
routes/web.py) should return Prism views orhtml(...). - API routes (
routes/api.py) should returndict/list/json(...).
Throwing an HttpException on an API route still yields the locked JSON envelope {message, status, errors?}.
Redirects
Section titled “Redirects”redirect(to) resolves to through url() so APP_BASE_PATH is honored:
return redirect("/dashboard") # → /apps/progress/dashboard when mountedHeaders and status
Section titled “Headers and status”return json({"ok": True}, status=201, headers={"X-Demo": "1"})return html("<p>Gone</p>", status=410)Related
Section titled “Related”- Views — Prism templates
- URL Generation
- Error Handling