HTTP
HttpClient is an application service backed by the current platform transport.
Requests are explicit value objects and return Task<HttpResult>.
Send a request
Section titled “Send a request”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.
Describe request intent
Section titled “Describe request intent”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.
Separate responses from transport errors
Section titled “Separate responses from transport errors”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.
Follow component lifetime
Section titled “Follow component lifetime”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.

