Declare + start
Builder supplies a finite target snapshot; Core validates capability, targets and bounds before readiness.
Product knowledge · Advanced · Service-owned outbound
Application selects the logical dependency and business policy. CoAkka HTTP Runtime owns the bounded target registry, endpoint/DNS/pool/TLS mechanics, request progress and typed terminal outcome.
01 · Ownership model
Names dependencies; owns authorization/credential intent, request meaning, status mapping, idempotency and retry policy.
Validates target snapshots; owns endpoint selection, DNS, pools, TLS, redirects, HTTP framing, deadlines and terminal facts.
Projects natural builders, requests and terminals while protecting type, buffer, callback and owner lifetime.
Owns its HTTP response and business effect. A received response is not automatically business success.
Do not call this surface CoAkka HTTP Client. These are outbound APIs of a CoAkka HTTP Runtime service; CoAkka HTTP Client is a separate planned product.
02 · Logical target declaration
logical target: sample.upstream · generation 1
endpoint: loopback
connect: 127.0.0.1:<port>
HTTP authority: 127.0.0.1:<port>
security: plaintext for this local example
incoming request data ──X──► arbitrary scheme/host/portLogical targets are construction-time snapshots. A handler selects a declared dependency name; it never turns caller query, headers or body into an arbitrary outbound destination.
03 · Target fields
sample.upstream; requests use it instead of an arbitrary URL.SINGLE_OWNER selects one eligible owner; WEIGHTED_ROUND_ROBIN distributes using relative endpoint weights when multiple candidates exist.04 · Request intent
submit:
logical target = sample.upstream
method = GET
path/query = /orders/A%2FB?view=summary
headers/body = bounded application values
call deadline = 3000 ms
returns: call identity · not an HTTP responseResolve variables and URL-encode values before submit. Never put /orders/{id}, an arbitrary full URL or raw untrusted text in the path/query field.
05 · Request fields
| Field | Meaning |
|---|---|
| Logical target | Selects a declared dependency snapshot, not an arbitrary socket. |
| Method | HTTP method of the call; it does not prove the operation is safe or idempotent to retry. |
| Path/query | Concrete encoded origin-form request target; no fragment or route syntax. |
| Headers/body | Ordered bounded HTTP values; application owns auth token, media type, codec and secret policy. |
| Call deadline | Finite monotonic operation budget; distinct from reader wait and inbound handler/transport timeouts. |
| Call identity | Opaque slot/generation returned after accepted admission; use it to match the exact terminal. |
06 · Call lifecycle
Builder supplies a finite target snapshot; Core validates capability, targets and bounds before readiness.
Core admits or refuses the request and returns a call identity. No remote response exists yet.
Core selects an endpoint, resolves/connects, applies security, sends the request and reads a bounded response under deadline.
One typed terminal tied to call identity reports cause, phase and certainty plus an optional HTTP response.
07 · Terminal facts
ADMISSION, PROVIDER_ADOPTION, TRANSPORT, RESPONSE, CANCELLATION, SHUTDOWN.404/500 can still be RESPONSE.Preserve unknown numeric enum values for forward compatibility; never coerce one into a known category.
08 · Exact terminal vocabulary
| Dimension | Stable values and meaning |
|---|---|
| Reason | RESPONSE; PROVIDER_FAILURE/PROVIDER_REJECTED/INVALID_PROVIDER_RESULT; CANCELLED/DEADLINE_EXCEEDED/STOPPED; RESPONSE_HEAD_LIMIT/RESPONSE_BODY_LIMIT/RESPONSE_AGGREGATE_LIMIT; OUT_OF_MEMORY; CLOCK_FAILURE. |
| Retry | NEVER, IF_SAFE, DELIVERY_UNCERTAIN. This is transport disposition; IF_SAFE still requires application proof of safe/idempotent behavior. |
| Certainty | NO_REQUEST_BYTES_SENT, REQUEST_UNCERTAIN, RESPONSE_HEAD_OBSERVED, COMPLETE_RESPONSE. These describe wire evidence, not business commit state. |
| Provider code / diagnostic | Bounded operator evidence; never branch business logic on diagnostic text or copy it into a public response. |
09 · Capacity and time
| Boundary | Required law |
|---|---|
| Target registry / endpoints | Finite declared entries; invalid or unsupported targets fail closed. |
| DNS / connections / pools | Finite work, connections and retained idle state; exact target owns capability/effective facts. |
| In-flight calls | Finite ceiling; pressure/refusal never becomes a hidden application queue. |
| Redirects | Finite hop/policy bound; authority, credential scope and TLS identity remain valid. |
| Response | Finite header/body/retained-terminal bytes; application never collects past the ceiling. |
| Call deadline | Operation progress budget. A deadline terminal differs from reader wait timeout. |
| Terminal reader wait | Window for retrieving an event; expiry only means no terminal was observed in that window. |
10 · DNS, TLS and redirects
DNS/IP/port used to open the connection; it can differ from HTTP authority.
Logical Host/authority and virtual hosting; never infer it from a resolved IP.
Certificate identity verified with trust roots; an mTLS client identity is separate material.
Every hop remains bounded and follows configured trust/credential policy; never forward a secret by guesswork.
Feature-check outbound and security providers on the exact package. Never put private keys, tokens, raw credentials or operator-only TLS diagnostics in a public response.
Advanced · Outbound HTTP
Run a local upstream first. Each CoAkka caller declares upstream with a fixed address and authority, submits one GET, then reads the matching result. The example never takes an arbitrary URL from the incoming request.
mkdir -p upstream-lab
printf 'hello upstream\n' > upstream-lab/hello.txt
python3 -m http.server --protocol HTTP/1.1 8091 --bind 127.0.0.1 --directory upstream-labUse the verified SDK 2.3.0. Save outbound.c in a second terminal’s project folder. The same C ABI source builds with either compiler on Linux and macOS.
#include <coakka/http/host.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static coakka_http_host_bytes_t bytes(const char *text) {
coakka_http_host_bytes_t span;
span.data = (const uint8_t *)text;
span.size = strlen(text);
return span;
}
static bool check(coakka_http_host_status_t status, const char *operation) {
if (status == COAKKA_HTTP_HOST_OK) {
return true;
}
fprintf(stderr, "%s: %s\n", operation, coakka_http_host_status_name(status));
return false;
}
static bool request_once(coakka_http_host_service_t *service) {
coakka_http_host_outbound_request_t request;
coakka_http_host_outbound_request_init(&request);
request.logical_target = bytes("upstream");
request.method = bytes("GET");
request.target = bytes("/hello.txt");
request.timeout_ms = 3000U;
coakka_http_host_outbound_call_t call;
if (!check(coakka_http_host_submit_outbound(service, &request, &call),
"submit outbound request")) {
return false;
}
coakka_http_host_outbound_event_t event;
coakka_http_host_outbound_event_init(&event);
if (!check(coakka_http_host_take_outbound(service, 5000U, &event),
"take outbound result")) {
return false;
}
const bool matched =
event.call.slot == call.slot && event.call.generation == call.generation;
const bool replied =
matched && event.reason == COAKKA_HTTP_HOST_OUTBOUND_RESPONSE;
if (replied) {
printf("HTTP %u\n", (unsigned)event.response_status);
if (event.response_status == 200U && event.response_body.size != 0U) {
// The response body is borrowed until the result is released.
fwrite(event.response_body.data, 1U, event.response_body.size, stdout);
}
} else {
fprintf(stderr,
"Outbound result: matched=%d reason=%" PRIu32 " phase=%" PRIu32
"\n",
(int)matched, event.reason, event.phase);
}
const bool released =
check(coakka_http_host_release_outbound(service, &event),
"release outbound result");
return replied && released;
}
int main(void) {
coakka_http_host_outbound_endpoint_t endpoint;
coakka_http_host_outbound_endpoint_init(&endpoint);
endpoint.node_id = bytes("local");
endpoint.connect_host = bytes("127.0.0.1");
endpoint.connect_port = 8091U;
endpoint.http_authority = bytes("127.0.0.1:8091");
endpoint.available = 1U;
coakka_http_host_outbound_target_t target;
coakka_http_host_outbound_target_init(&target);
target.name = bytes("upstream");
target.generation = 1U;
target.endpoints = &endpoint;
target.endpoint_count = 1U;
coakka_http_host_configuration_t configuration;
coakka_http_host_configuration_init(&configuration);
configuration.bind_address = bytes("127.0.0.1");
configuration.outbound_targets = ⌖
configuration.outbound_target_count = 1U;
coakka_http_host_service_t *service = NULL;
uint32_t failed_route = COAKKA_HTTP_HOST_FAILED_INDEX_NONE;
if (!check(coakka_http_host_service_create(&configuration, NULL, 0U, &service,
&failed_route),
"create outbound service")) {
return EXIT_FAILURE;
}
coakka_http_host_issue_t issue;
coakka_http_host_issue_init(&issue);
const bool replied =
check(coakka_http_host_service_start(service, &issue), "start service") &&
request_once(service);
const bool closed =
check(coakka_http_host_service_destroy(&service), "destroy service");
return replied && closed ? EXIT_SUCCESS : EXIT_FAILURE;
}
cc -std=c11 -I"$COAKKA_HTTP_SDK/include" outbound.c -L"$COAKKA_HTTP_SDK/lib" \
-Wl,-rpath,"$COAKKA_HTTP_SDK/lib" -lcoakka_http_host -o outbound-c
./outbound-cc++ -x c++ -std=c++20 -I"$COAKKA_HTTP_SDK/include" outbound.c -L"$COAKKA_HTTP_SDK/lib" \
-Wl,-rpath,"$COAKKA_HTTP_SDK/lib" -lcoakka_http_host -o outbound-cpp
./outbound-cppUse the 2.3.2 JVM project. Save the file under src/main/kotlin or src/main/java, in the study/ directory. The commands default to macOS ARM64. On Pi, add -Dcoakka.target=linux-aarch64 to Maven or -PcoakkaTarget=linux-aarch64 to Gradle.
package study
import coakka.http.OutboundEndpoint
import coakka.http.OutboundReason
import coakka.http.OutboundRequest
import coakka.http.OutboundStrategy
import coakka.http.OutboundTarget
import coakka.http.ServiceBuilder
fun main() {
val endpoint = OutboundEndpoint(
nodeId = "local",
connectHost = "127.0.0.1",
connectPort = 8091,
httpAuthority = "127.0.0.1:8091",
)
val target = OutboundTarget(
name = "upstream",
generation = 1,
strategy = OutboundStrategy.SINGLE_OWNER,
endpoints = listOf(endpoint),
)
ServiceBuilder().listen("127.0.0.1", 0).outboundTarget(target).start().use { service ->
val call = service.submitOutbound(OutboundRequest(
logicalTarget = "upstream",
method = "GET",
target = "/hello.txt",
timeoutMillis = 3_000,
))
val result = checkNotNull(service.takeOutbound(5_000)) { "Missing outbound result" }
check(result.call == call) { "Result belongs to a different call" }
check(result.reason == OutboundReason.RESPONSE) { "Outbound request ended: ${result.reason}" }
println("HTTP ${result.responseStatus}")
if (result.responseStatus == 200) print(result.responseBody().toString(Charsets.UTF_8))
}
}
mvn -q compile dependency:build-classpath -Dmdep.outputFile=target/classpath.txt
java -Djava.library.path=target/coakka-native/native \
-cp "target/classes:$(cat target/classpath.txt)" study.KotlinOutboundKt./gradlew runKotlinOutboundUse the 2.3.2 JVM project. Save the file under src/main/kotlin or src/main/java, in the study/ directory. The commands default to macOS ARM64. On Pi, add -Dcoakka.target=linux-aarch64 to Maven or -PcoakkaTarget=linux-aarch64 to Gradle.
package study;
import coakka.http.Headers;
import coakka.http.OutboundCallId;
import coakka.http.OutboundEndpoint;
import coakka.http.OutboundReason;
import coakka.http.OutboundRequest;
import coakka.http.OutboundStrategy;
import coakka.http.OutboundTarget;
import coakka.http.OutboundTerminal;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
public final class JavaOutbound {
private JavaOutbound() {}
public static void main(String[] args) throws Exception {
OutboundEndpoint endpoint = new OutboundEndpoint(
"local", "127.0.0.1", 8091, "127.0.0.1:8091");
OutboundTarget target = new OutboundTarget(
"upstream", 1L, OutboundStrategy.SINGLE_OWNER, Collections.singletonList(endpoint));
Service service = new ServiceBuilder()
.listen("127.0.0.1", 0)
.outboundTarget(target)
.start();
try {
OutboundCallId call = service.submitOutbound(new OutboundRequest(
"upstream", "GET", "/hello.txt", new Headers(), new byte[0], 3_000));
OutboundTerminal result = service.takeOutbound(5_000L);
if (result == null || !result.getCall().equals(call)) {
throw new IllegalStateException("Missing result for this call");
}
if (result.getReason() != OutboundReason.RESPONSE) {
throw new IllegalStateException("Outbound request ended: " + result.getReason());
}
System.out.println("HTTP " + result.getResponseStatus());
if (result.getResponseStatus() == 200) {
System.out.print(new String(result.responseBody(), StandardCharsets.UTF_8));
}
} finally {
service.close();
}
}
}
mvn -q compile dependency:build-classpath -Dmdep.outputFile=target/classpath.txt
java -Djava.library.path=target/coakka-native/native \
-cp "target/classes:$(cat target/classpath.txt)" study.JavaOutbound./gradlew runJavaOutboundFor other languages, open the complete outbound exercise: Go · Python · Node.js · Bun · C# · Swift.
With the file present, expect HTTP 200 and hello upstream. Rename hello.txt and repeat: HTTP 404 is still a response, not a transport failure. Stop the upstream and repeat to see a non-response outcome. A read deadline is not permission to replay an application operation.
11 · Cancellation, retry and idempotency
Cancellation is intent until the matching terminal confirms outcome. Do not free caller state while Core still owns the call.
Expiry does not prove the remote missed the request or effect; the response may have been lost on return.
Create a new attempt/call identity with bounded attempts, backoff and total budget; retain a business idempotency key when required.
For charge/create/non-idempotent work with ambiguous outcome, read authoritative business state before repeating.
12 · Failure law
| Observed outcome | Meaning / next action |
|---|---|
| Startup target refusal | Declaration, capability or bound is invalid; the candidate service is not ready. |
| Synchronous submit refusal | Call was not admitted; inspect stable category and pressure/closed state. |
| Transport/provider terminal | No HTTP response; branch on reason/phase/retry/certainty and repair the network/security/provider owner. |
| HTTP 4xx/5xx response | Remote returned an HTTP response; application decides business mapping and retry. |
| Cancel/deadline terminal | Preserve ambiguity; never infer rollback or exactly-once. |
| Reader wait timeout | No terminal arrived during the wait window; never submit a duplicate automatically. |
| Close/drain refusal | Retain service, call and application owners until cleanup converges. |
13 · Integration checklist