Skip to content

HTTP

HttpClient is an application service backed by the current platform transport. Requests are explicit value objects and return Task<HttpResult>.

Task<void> LoadFeed(State<std::string> output) {
auto http = UseService<HttpClient>();
HttpResult result = co_await http->Send({
.url = "https://example.com/feed.json",
.method = HttpMethod::Get,
});
if (result.HasResponse()) {
output = result.Response().body;
} else {
output = result.Error().message;
}
}

Launch the task through UseTaskScope() so cancellation follows the component that requested the data.

Specify method, headers, body, and optional timeout in HttpRequest. Use HttpMethod for standard methods and provide binary body data only when the remote API requires it.

The transport follows platform networking policy. Browser CORS, application transport security, Android network security, certificate trust, redirects, and proxy behavior remain platform concerns rather than shared-runtime bypasses.

A response contains final URL, status code, headers, and body. HTTP status codes, including 4xx and 5xx, are valid responses and remain available through Response(). DNS, connection, timeout, cancellation, malformed request, and unavailable-transport failures use HttpError.

Inspect HasResponse() before accessing a response and preserve an error message appropriate for the user instead of displaying low-level transport diagnostics directly.

The runtime installs HttpClient as a root service; obtain it with UseService<HttpClient>(). Capture the shared service and controlled state by value in a task. Never put credentials in documentation, client source literals, or generated Web output.

See the HTTP API for exact request and result methods and Tasks for cancellation ownership.