Companion

object Companion

Factories for the common response shapes.

Functions

Link copied to clipboard
fun bytes(body: ByteArray, contentType: MediaType? = null, status: Int = 200, headers: Headers = Headers.EMPTY): DebugResponse

A response carrying arbitrary body bytes, with the given contentType (default application/octet-stream), status (default 200), and headers (default empty).

Link copied to clipboard
fun cursorEnvelope(currentSequence: Long, clientCursor: String?, state: String? = null, epoch: Long = CursorCodec.processEpoch, appendItems: StringBuilder.() -> Unit): DebugResponse

A cursor-envelope response for observable list routes (the wire protocol's live-polling shape): {"cursor":..,"status":..,("items":[..],)?(,"state":..)?}.

Link copied to clipboard
fun error(message: String, status: Int = 400, code: String? = null, field: String? = null, hint: String? = null): DebugResponse

An enveloped error response. The body is the uniform error envelope JSON {"error":<type>,"message":...,"code":?,"field":?,"hint":?}, where <type> follows from status: bad_request (400), unauthorized (401), forbidden (403), not_found (404), method_not_allowed (405), conflict (409), payload_too_large (413), unprocessable_entity (422), too_many_requests (429), internal_error (500), unavailable (503), timeout (504), and error for any other status. Optional code, field, and hint keys are omitted when null. All string values are escaped via escapeForJson.

Link copied to clipboard
fun json(status: Int = 200, build: StringBuilder.() -> Unit): DebugResponse

A application/json; charset=utf-8 response whose body is built by applying build to a StringBuilder, with the given status (default 200).

Link copied to clipboard
fun notFound(message: String = "Not found"): DebugResponse

A 404 enveloped error response. The body is the uniform error envelope JSON with message (default "Not found").

Link copied to clipboard
fun ok(json: String, status: Int = 200): DebugResponse

A application/json; charset=utf-8 response carrying the already serialized json string, with the given status (default 200).

Link copied to clipboard
fun streamEnvelope(total: Long, retained: Int, clientCursor: String?, state: String? = null, epoch: Long = CursorCodec.processEpoch, appendItems: StringBuilder.(from: Int, reset: Boolean) -> Int): DebugResponse

A stream-envelope response for a route whose list only grows at its end, such as a log: {"cursor":..,"status":..,("items":[..],)?("dropped":n,)?("state":..)?}.

Link copied to clipboard
fun text(body: String, status: Int = 200, contentType: MediaType? = null): DebugResponse

A text response carrying body, with the given status (default 200) and contentType (default text/plain; charset=utf-8).