The HTTP client
Status: built 2026-10-10. Confirmed defaults (2026-10-09): a blocking API on virtual threads
over Vert.x; a standalone library plus a thin framework adapter; retries for idempotent requests
only by default; a client per consumed service; auth strategies with token caching and refresh;
JSON with the framework’s Jackson 3; timeouts; Context propagation; convenience methods. Wanted
before M4c (login uses it).
1. Modules and the new dependency
Section titled “1. Modules and the new dependency”| Module | Contents | Depends on |
|---|---|---|
framework-httpclient |
the library: HttpClients, ServiceClient, requests, responses, auth, retries |
io.vertx:vertx-core, Jackson 3, SLF4J API, JSpecify. Not framework-core: usable without the framework |
framework-httpclient-module |
HttpClientModule (id http-client): configured clients as named instances, Context propagation, metrics, lifecycle |
framework-core, framework-httpclient |
New third-party dependency: Vert.x core (5.1.x) and through it Netty. Why: the maintainers chose
Vert.x for the client (connection pooling, HTTP/1.1 and HTTP/2, a non-blocking core that many
virtual threads can share without a thread per connection); java.net.http was the alternative and
was not chosen. Vert.x appears in no public signature of the library: callers see only framework
types and JDK types, so the engine can be replaced. The version is managed in framework-bom.
2. The library
Section titled “2. The library”try (HttpClients clients = HttpClients.create) { ServiceClient orders = clients.service(ServiceOptions.builder("orders", URI.create("https://orders.example.com")).build); Order order = orders.get("/orders/{id}").pathParam("id", "42").send.json(Order.class);}HttpClientsowns one Vert.x instance and its pools;AutoCloseable; thread-safe; create one per application.service(ServiceOptions)returns aServiceClientfor one consumed service.ServiceOptions(record + builder):name([a-z][a-z0-9-]*),baseUrl(absolutehttporhttps, a host, no user info, no query or fragment; its path is a prefix),connectTimeout(default5s),requestTimeout(default30s, per attempt, the whole exchange including the body),maxResponseBytes(default 10 MiB, at most 1 GiB),retry(RetryPolicy),auth(Auth, default none), default headers.- Requests:
client.get(path),post,put,patch,delete,head, andrequest(method, path)return aRequestBuilder:pathParam(name, value),query(name, value)(repeatable),header(name, value),json(Object),body(bytes, contentType),form(Map),idempotencyKey(key),retryable(boolean),timeout(Duration), thensend.- The path must start with
/and is appended to the base URL’s path. It may not contain//,?,#,..or.segments, or\; a request can never leave its service’s host (the SSRF rule: a request URL is never taken from input). {name}placeholders are filled bypathParam, percent-encoded as one segment (every character except unreserved ones, so/,?,#and%are encoded). A value that is empty,.or..isIllegalArgumentException. An unfilled placeholder, or apathParamfor a name the path does not have, isIllegalArgumentException.- Header names are tokens; header values may not contain CR, LF or NUL (
IllegalArgumentException: no header injection).Host,Content-Length,Transfer-EncodingandConnectionare set by the client and refused.
- The path must start with
ClientResponse:status,header(name),headers(name),headers()(every header by lower-case name, unmodifiable),bodyBytes,bodyText(UTF-8),json(Class<T>)/json(TypeReference),isSuccess(2xx).sendnever throws for an HTTP status; a non-2xx answer is a response.- Convenience:
sendJson(Class<T>)returns the decoded body of a 2xx response and throwsUnexpectedStatusException(status, service, method, path template, and theerrorcode of the platform’s error envelope when the body has one) otherwise; the exception never carries the body.ServiceClient.getJson(path, type, pathParams...)andpostJson(path, body, type)are shorthands. - JSON is Jackson 3 configured like the framework’s (ISO dates) but tolerant on read
(unknown properties ignored: another service may add fields).
ServiceOptions.mapperreplaces it. - Failures are
HttpClientException(unchecked) with aKind:CONNECT(could not connect),TIMEOUT,RESPONSE_TOO_LARGE,IO(the exchange broke),DECODE(the body is not the JSON asked for; the parser’s message is not attached because it can quote the body),AUTH(an auth strategy could not get credentials; a supplier’s own exception is reduced to its class name),INTERRUPTED(the calling thread was interrupted; the flag is restored). Messages name the service, method and path template, never header values, bodies, tokens or query strings. - Using a client after its
HttpClientswas closed isIllegalStateException(“the HTTP client engine is closed”): a programming error, not a failure of the exchange. - Redirects are not followed (a redirect is returned as a response): following one could send
the
Authorizationheader to another host. - Logging: DEBUG per attempt: service, method, path template, status or failure kind, duration, attempt number. Never query strings, headers or bodies.
- Observation:
ServiceOptions.observer(ClientObserver)is told each finished attempt (service, method, path template, status orKind, nanoseconds, attempt); the adapter records metrics with it.
3. Retries
Section titled “3. Retries”RetryPolicy (record): maxAttempts (default 3, 1 to 10; 1 = no retry), initialBackoff
(200ms), maxBackoff (5s), maxRetryAfter (30s), retryOnStatuses (429, 502, 503, 504).
RetryPolicy.none turns retries off.
- Which requests may be retried: methods that are idempotent by definition (
GET,HEAD,OPTIONS,PUT,DELETE); a request with an idempotency key (idempotencyKey(key)sets theIdempotency-Keyheader); a request markedretryable(true).POSTandPATCHare never retried otherwise.retryable(false)turns retries off for one request. - What is retried:
CONNECT,TIMEOUTandIOfailures, and responses with a status inretryOnStatuses. When attempts run out, the last response is returned (or the last failure thrown). - Waits: exponential (
initialBackoff * 2^(n-1), capped atmaxBackoff) with full jitter. ARetry-Afterheader (seconds or an HTTP date) on a retried status is honoured when it is at mostmaxRetryAfter; when it is longer the response is returned at once rather than waited for. - Waiting is interruptible (
INTERRUPTED).
4. Auth
Section titled “4. Auth”Auth is applied to every attempt. Strategies:
| Strategy | Sends |
|---|---|
Auth.none |
nothing |
Auth.bearer(Supplier<String> token) |
Authorization: Bearer <token>, the supplier asked per attempt (for example platform::accessToken) |
Auth.bearer(token, Runnable onUnauthorized) |
as above; on a 401 the runnable runs (clear a cached token) and the request is sent once more |
Auth.basic(user, Supplier<String> password) |
Authorization: Basic ... |
Auth.header(name, Supplier<String> value) |
an API-key header |
Auth.clientCredentials(ClientCredentials) |
OAuth 2 client credentials (below) |
Client credentials: ClientCredentials.builder(tokenUrl, clientId, Supplier<String> clientSecret) with scope, audience, method (POST, the default: client_id and
client_secret in the form body, as the FlowCatalyst platform expects; or BASIC).
- The token is fetched with the same
HttpClients(its own connect and request timeouts: the service’s),grant_type=client_credentials, and cached untilexpires_inminus a skew ofmin(30s, expires_in / 10); withoutexpires_in, 5 minutes.token_type, when present, must beBearer(case-insensitive). - Single flight: concurrent callers needing a new token wait for one token request.
- A
401from the service drops the cached token and sends the request once more with a new token, for every method (a401means the request was refused, not processed). A second401is returned. - A failed token request (transport error, non-2xx, malformed answer) is
HttpClientException(AUTH); its message has the token URL’s host and the status, never the secret or the answer body. The token URL must behttps, orhttpto a loopback address (tests, local platforms).
5. The framework adapter
Section titled “5. The framework adapter”Amended 2026-10-14 (config and code, section 3.9): clients are named in code,
HttpClientModule.builder.client(name, HttpClientOptions), with timeouts, size limit, retry
and the auth strategy (ClientAuth) as code. Configuration keeps, per client,
http-clients.instances.<name>.base-url and the credentials of its auth strategy; the engine
settings http-client.* are builder calls.
HttpClientModule provides HttpClients (closed at shutdown) and ServiceClients, a registry
of configured clients (core contract section 2, default driver http):
http-clients: instances: billing: base-url: https://billing.example.com request-timeout: 10s retry: { max-attempts: 3, initial-backoff: 200ms } auth: { type: client-credentials, token-url: https://login.example.com/oauth/token, client-id: orders-service, scope: billing } # client-secret: a secret, from env- Keys:
base-url(required),connect-timeout,request-timeout,max-response-bytes,retry.max-attempts,retry.initial-backoff,retry.max-backoff,retry.max-retry-after;auth.typenone(default),bearer(auth.token, secret),basic(auth.username,auth.passwordsecret),header(auth.name,auth.valuesecret),client-credentials(auth.token-url,auth.client-id,auth.client-secretsecret,auth.scope,auth.audience,auth.methodpost/basic). Unknown keys fail start-up, as for every capability. ServiceClients.get(name)returns the configured client;get(name, Context)returns it withX-Correlation-Idset to the context’s correlation id on every request (only that: the client id is not sent to other services by default).register(name, ServiceOptions)adds a client built in code (for example withAuth.bearer(platform::accessToken, platform::clearToken)).- Metrics (background-and-metrics contract):
fw_http_client_requests_total{service, method, outcome}(outcomethe status code, or the failure kind in lower case) andfw_http_client_request_duration_seconds{service, method}, one per attempt.
5a. As built (2026-10-10)
Section titled “5a. As built (2026-10-10)”-
Engine settings of the adapter:
http-client.event-loops(default 2, 1 to 64) andhttp-client.max-connections-per-host(default 50, 1 to 1000); the library’sHttpClients.Settingstakes the same plus a monotonic and a wall clock (the adapter passes the application’s). -
ServiceClients.register(ServiceOptions)returns the client; the options’ own observer is replaced by the metrics observer.ServiceClients.nameslists configured and registered clients. -
Registered clients can be removed (2026-10-20):
unregister(name)(false when absent, throws for a configured client),replace(options)(register or swap) andregisterScoped(options)(Registration,AutoCloseable). Removal drops the client’sserviceseries from both client metrics (Counter.removeSeries/Timer.removeSeries, new default methods that return 0 for a driver keeping no series); a held reference keeps working, unmeasured. Serialised on the registry lock; each client’s observer is retired under its own lock so no attempt re-creates a series. -
Every request carries
User-Agent: flowcatalyst-framework-httpclient. Gzip and deflate answers are decompressed (the size limit applies to the bytes received). -
A
RESPONSE_TOO_LARGEfailure is never retried (a larger answer will not get smaller). -
The repeat after a
401does not count as a retry attempt. -
Capture (2026-10-30):
HttpCapture.CURRENT(aScopedValue<Sink>) bound around work makesServiceClienthand every attempt to the sink as anHttpCapture.Exchange(URL with query, headers as sent, bodies, status or failure kind, attempt number). Sensitive header values are[redacted]; a throwing sink is logged and ignored; unbound costs oneisBoundcheck.
6. Tests
Section titled “6. Tests”Against a real local HTTP server (the JDK’s com.sun.net.httpserver): every method, JSON both ways,
path and query encoding and the refused paths and values, header injection refused, response size
limit, timeouts, connect failures, retries (idempotent methods, idempotency key, POST not retried,
Retry-After honoured and too long, attempts exhausted), redirects not followed, every auth strategy,
client credentials (cached, refreshed after expiry, single flight under concurrency, 401 retried
once, a failing token endpoint whose message holds no secret), UnexpectedStatusException without
the body, the adapter’s configuration, Context propagation and metrics. TLS is not exercised by a
test (no certificate fixture); https base URLs use Vert.x’s TLS with host verification and the
JDK’s default trust store.