Skip to content

Http Outgoing

1 min read

Import: import system.webapi;

See the Web APIs guide for runnable examples, lifecycle, and error behavior.

HttpOutgoing

Outbound HTTP response built by handlers and middleware.

public class HttpOutgoing

status

HTTP response status code.

public status: int

headers

HTTP headers associated with this message.

public headers: HttpHeaders

body

Text response body.

public body: string

body_bytes

Binary response body; use bytes to construct a binary response.

public body_bytes: byte[]

constructor

Creates a HttpOutgoing with status, body.

public constructor(status: int, body: string = "")

set_header

Sets a response header and returns this response for chaining.

public fun set_header(name: string, value: string): HttpOutgoing

text

Creates a plain-text response with status 200 unless another status is supplied.

public static fun text(body: string, status: int = 200): HttpOutgoing

html

Creates an HTML response with status 200 unless another status is supplied.

public static fun html(body: string, status: int = 200): HttpOutgoing

json_text

Creates a JSON response from already encoded JSON text; does not serialize or validate the text.

public static fun json_text(body: string, status: int = 200): HttpOutgoing

detail

FastAPI-style {"detail": "..."} JSON error.

public static fun detail(message: string, status: int = 500): HttpOutgoing

from_body_error

A 400 response for a failed body read; invalid input such as a form over its limits keeps the failure message as the detail.

public static fun from_body_error(error: IoError): HttpOutgoing

from_validation

A structured validation response, prefixed with the input source.

public static fun from_validation(errors: ValidationErrors, source: string): HttpOutgoing

invalid_input

Creates a 422 validation-error response describing the invalid input and its location.

public static fun invalid_input(
    source: string,
    name: string,
    code: string,
    message: string
): HttpOutgoing

already_sent

Creates a marker indicating that the response has already been sent.

public static fun already_sent(): HttpOutgoing

bytes

Creates a binary response from data, with status 200 by default.

public static fun bytes(data: byte[], status: int = 200): HttpOutgoing

from_status

Creates a response using the supplied status code and message.

public static fun from_status(st: HttpStatus): HttpOutgoing

not_found

Creates a 404 Not Found response.

public static fun not_found(): HttpOutgoing

method_not_allowed

Creates a 405 Method Not Allowed response whose Allow header lists allowed, the methods that the requested path accepts, separated by ,.

public static fun method_not_allowed(allowed: List<string>): HttpOutgoing

empty

Creates a response without a body, with status 204 by default.

public static fun empty(status: int = 204): HttpOutgoing