The HTTP Core module in Xeno configures outgoing HTTP requests to external
REST APIs and remote services. It combines an IHttpClient implementation based
on Axios with an IServiceResilience implementation based on Cockatiel.
RemoteDataSource uses both services and returns remote payloads inside
ResultType<T> values.
HTTP Core abstracts external HTTP communication behind IHttpClient and
RemoteDataSource. The current built-in transport is AxiosHttpClient; the
contracts remain independent of the concrete transport implementation.
When an application service or repository executes an external HTTP call:
Remote Data Source Invocation: A repository or integration service
extends RemoteDataSource and calls typed methods such as get, post,
put, patch, or delete.
Resilience Policy Wrapping (Cockatiel): ServiceResilience executes the
HTTP operation through the configured bulkhead, circuit breaker, and retry
policy chain.
HTTP Transport Execution (AxiosHttpClient): The client applies the
configured base URL, headers, timeout, query parameters, abort signal, and
response validation to the Axios request.
Result Mapping: RemoteDataSource returns response.data wrapped in
Result.ok(). Transport and resilience exceptions propagate to the caller.
sequenceDiagram
autonumber
participant App as Application / Remote Repository
participant RDS as RemoteDataSource
participant Res as ServiceResilience (Cockatiel)
participant Ax as AxiosHttpClient (Axios)
participant Ext as External REST API / Microservice
The built-in IHttpClient implementation that encapsulates an axios instance.
It applies the configured base URL, default headers, timeout, query parameters,
abort signal, redirects, decompression, and credentials settings. It converts
successful Axios responses into HttpResponse<T> and maps HTTP or transport
failures to AppError.
The IServiceResilience implementation built on top of Cockatiel. It
executes an operation through the configured policy chain, including:
Bulkhead Policy: Limits concurrent operations.
Circuit Breaker Policy: Opens after the configured number of consecutive
transient failures and later permits a half-open recovery attempt.
Retry Policy: Retries transient and idempotent HTTP operations using
exponential backoff. Transient failures include network errors, status 408,
status 429, and 5xx responses.
The current resilience configuration does not define a fallback policy. Request
timeouts are provided by the HTTP client configuration or an AbortSignal, not
by a separate timeout property in ResilienceConfig.
The abstract base data source designed to be extended by infrastructure remote
repositories (e.g., PaymentRemoteDataSource, NotificationClient). It
combines IHttpClient and IServiceResilience into a unified helper interface
for executing typed HTTP operations (get, post, put, patch, delete).
Each method returns Promise<ResultType<TResponse>>.
The framework container module responsible for registering the configured HTTP
client and resilience singleton inside the Dependency Injection Container. The
current HttpCoreModule invokes HttpUtils.addAxios() and
HttpUtils.addResilience(); application-specific RemoteDataSource instances
are registered separately.
Registering and Configuring HTTP Core via AppBuilder
HttpCoreModule registers the HTTP client and resilience service during the
priority 30 AppBuilder phase. RemoteDataSource instances are application
services and must be registered separately after those dependencies are
available, for example through addServices() at priority 99.
The current implementation has these constraints:
opts.http.token must be defined when HttpCoreModule is configured;
retry applies only to transient failures on idempotent methods: GET, PUT,
DELETE, HEAD, and OPTIONS;
POST and PATCH failures are not retried by the built-in retry predicate;
RemoteDataSource returns the response payload in ResultType<T> but does
not convert transport or resilience exceptions into failed Results;
dataSourceToken exists in HttpCoreConfig, but the current
HttpCoreModule does not execute it automatically;
tracing headers are not injected automatically by AxiosHttpClient;
fallback and a dedicated resilience timeout policy are not available in the
current ResilienceConfig.
Built-in Resilience (Cockatiel Integration) HTTP Core provides
configurable bulkhead, circuit breaker, and conditional retry policies for
operations executed through RemoteDataSource.
Agnostic HTTP ContractIHttpClient isolates application code from the
concrete Axios transport and normalizes successful responses as
HttpResponse<T>.
Standardized Remote Data Source (RemoteDataSource) Infrastructure
repositories can reuse a typed API that combines HTTP transport and
resilience, returning ResultType<TResponse> values.
Centralized Client Configuration and Dependency Injection Base URLs,
headers, timeouts, transport options, and resilience thresholds are
configured through AppBuilder.addHttpCore().
Warning: HTTP Core dependencies HTTP Core requires axios and cockatiel
at runtime. Install them in the application workspace when enabling
.addHttpCore():
Terminal window
npminstallaxioscockatiel
If either dependency is missing, module resolution fails when Xeno creates the
HTTP client or resilience implementation.
Xeno is an MIT-licensed open source project. It can grow thanks to the support
of these awesome people. If youβd like to join them, please read more at
support section