BilldogEng.Transport (BilldogEng v1.0.0-beta.1)

Copy Markdown View Source

Thin HTTP client around Erlang's :httpc with:

  • per-request timeout
  • optional gzip request bodies (only when the body is large enough to benefit)
  • exponential backoff retry (1s, 2s, 4s …) for 5xx / 429 / network errors
  • unwrapping of the {success, data, meta} envelope when present

Mirrors the Node SDK transport.ts. A :sleep_fn may be injected (tests) to avoid real backoff delays.

Summary

Functions

Build a resolved transport config map from options.

Perform a POST request with retry/backoff. Returns {:ok, parsed} (envelope unwrapped) or {:error, %BilldogEng.Error{}}.

Types

config()

@type config() :: %{
  host: String.t(),
  request_timeout: non_neg_integer(),
  gzip: boolean(),
  max_retries: non_neg_integer(),
  enable_logging: boolean(),
  sleep_fn: (non_neg_integer() -> any())
}

Functions

config(opts)

@spec config(keyword()) :: config()

Build a resolved transport config map from options.

request(config, opts)

@spec request(
  config(),
  keyword()
) :: {:ok, term()} | {:error, BilldogEng.Error.t()}

Perform a POST request with retry/backoff. Returns {:ok, parsed} (envelope unwrapped) or {:error, %BilldogEng.Error{}}.

Options:

  • :path — required, path appended to host (e.g. "/ingest-events")
  • :body — the request body (will be JSON-encoded), or nil for a GET
  • :headers — extra headers (list of {name, value} string tuples)
  • :gzip — per-call override; defaults to true (honored only if config gzip)