Responses¶
Return whatever the handler has. Aether decides how to send it.
| returned | sent as |
|---|---|
dict, list, str, int, and friends |
JSON, serialized in Rust |
| a pydantic model | JSON, through pydantic's own serializer |
None |
204 No Content |
Response |
exactly what it says |
SSE |
a text/event-stream that stays open |
Explicit responses¶
Return a Response when you need a specific status code, a content type that
is not JSON, or bytes that are already encoded and should not be touched.
from aether import Response
@app.get("/teapot")
async def teapot(_: Request):
return Response(b"short and stout", status=418, content_type="text/plain")
Custom headers go alongside:
body may be bytes or str; a str is encoded as UTF-8.
Status codes you get for free¶
204when a handler returnsNone404when nothing matches the path405, with anAllowheader, when the path exists for another method413when the body is over the limit422when a parameter or body fails validation426on a plainGETto a WebSocket route500when the handler raises, with no detail in the body503, withRetry-After, when every worker is at its concurrency limit504when a handler does not respond withinrequest_timeout