fastware v0.1.0 /src.fastware.responses
On this page

HTTP response types including JSON, text, HTML, bytes, and streaming responses, plus cookie helpers and low-level ASGI send functions.

#src.fastware.responses

#src.fastware.responses

HTTP response types including JSON, text, HTML, bytes, and streaming responses, plus cookie helpers and low-level ASGI send functions.

python
def set_cookie(name: str, value: str, *, httponly: bool=False, samesite: str='lax', max_age: int | None=None, path: str='/', secure: bool=False) -> str

Build a Set-Cookie header string.

python
def delete_cookie(name: str, *, path: str='/') -> str

Build a Set-Cookie header string that clears the cookie.

#HTTPError

Raise from handlers to return a specific HTTP error status.

#JSONResponse

JSON response with optional status code, headers, and cookies.

#TextResponse

Plain text or CSS response.

headers (optional) is merged with the framework's default response headers; values must already be plain strings.

#HTMLResponse

HTML response.

#BytesResponse

Raw bytes response with an explicit content type.

#StreamResponse

Streaming response (for SSE).

#FileResponse

Serve a file from disk with MIME detection and Content-Length.

#_send_response

python
async def _send_response(send: Callable, status: int, body: bytes, content_type: str, extra_headers: dict[str, str] | None=None, cookies: list[str] | None=None) -> None

Send a complete HTTP response (headers + body).

#send_error

python
async def send_error(send: Callable, status: int, detail: str) -> None

Send a complete JSON error response via raw ASGI send calls.

Intended for use by middleware that needs to short-circuit with an error without constructing response objects.