Skip to main content

Response

The reply a handler returns. Build one with a factory (Response.text, .json, .html, .bytes, .error, .redirect, .file, .stream, .sse), add headers with with_header, return it. A Response is handed to the server once; reusing it raises RuntimeError.

__init__​

__init__(self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

bytes​

bytes(*args, **kwargs)

bytes(body: object, content_type: str, status: int = 200) -> clika_runtime._core.http.Response

bytes(body, content_type, status=200) -> Response

Raw bytes with an explicit content type.

error​

error(*args, **kwargs)

error(status: int) -> clika_runtime._core.http.Response

error(status) -> Response

A status-only response; the error handler renders its page.

file​

file(*args, **kwargs)

file(path: str) -> clika_runtime._core.http.Response

file(path) -> Response

Serve a file; the content type follows its extension. Contain path before deriving it from request input.

html​

html(*args, **kwargs)

html(body: object, status: int = 200) -> clika_runtime._core.http.Response

html(body, status=200) -> Response

A text/html response.

json​

json(*args, **kwargs)

json(body: object, status: int = 200) -> clika_runtime._core.http.Response

json(body, status=200) -> Response

An application/json response; a str or bytes body is sent as written, anything else goes through json.dumps.

redirect​

redirect(*args, **kwargs)

redirect(location: str, status: int = 302) -> clika_runtime._core.http.Response

redirect(location, status=302) -> Response

A redirect; location is sent as written, so validate it before building it from request input.

set_cookieset_cookie(self, name: str, value: str, *, path: str | None = None, domain: str | None = None, max_age: int | None = None, http_only: bool | None = None, secure: bool | None = None, same_site: str | None = None) -> object

set_cookie(self, name: str, value: str, *, path: str | None = None, domain: str | None = None, max_age: int | None = None, http_only: bool | None = None, secure: bool | None = None, same_site: str | None = None) -> object

set_cookie(name, value, *, path=None, domain=None, max_age=None, http_only=None, secure=None, same_site=None) -> Response

Set a cookie (one Set-Cookie header; a name may repeat) and return this response. An unset attribute keeps the server's default: Path=/, no Domain, a session cookie (no Max-Age), HttpOnly, not Secure, SameSite=Lax. same_site is 'lax', 'strict' or 'none' (any case).

sse​

sse(*args, **kwargs)

sse(events: object) -> clika_runtime._core.http.Response

sse(events) -> Response

A Server-Sent-Events body: events is an iterable of frames, each a str (the data) or a mapping with 'data' and, optionally, 'event' and 'id'.

stream​

stream(*args, **kwargs)

stream(content_type: str, chunks: object) -> clika_runtime._core.http.Response

stream(content_type, chunks) -> Response

A chunked body: chunks is an iterable (a generator) of str or bytes, one chunk per item, pulled on a server thread; an exception raised while producing aborts the stream.

text​

text(*args, **kwargs)

text(body: object, status: int = 200) -> clika_runtime._core.http.Response

text(body, status=200) -> Response

A text/plain response.

with_header​

with_headerwith_header(self, name: str, value: str) -> object

with_header(self, name: str, value: str) -> object

with_header(name, value) -> Response

Append a header and return this response (a name may repeat).