SetuClient.HTTP (Setu Client v1.0.0)

Copy Markdown View Source

Shared HTTP client used by all Setu SDK sub-modules.

Layers over Finch with rate limiting, full-jitter exponential backoff, structured SetuClient.Error decoding, and :telemetry spans.

Summary

Functions

Executes a JSON API request and decodes a 2xx response into a map.

Executes an HTTP request with retry and rate limiting.

Types

raw_response()

@type raw_response() :: %{
  status: non_neg_integer(),
  headers: [{String.t(), String.t()}],
  body: String.t()
}

Functions

json_request(method, url, extra_headers, body, cfg)

@spec json_request(
  atom(),
  String.t(),
  [{String.t(), String.t()}],
  map() | nil,
  SetuClient.Config.t()
) :: {:ok, map()} | {:error, SetuClient.Error.t()}

Executes a JSON API request and decodes a 2xx response into a map.

Returns {:ok, map()} or {:error, %SetuClient.Error{}}.

request(method, url, extra_headers, body, cfg)

@spec request(
  atom(),
  String.t(),
  [{String.t(), String.t()}],
  String.t() | nil,
  SetuClient.Config.t()
) ::
  {:ok, raw_response()} | {:error, SetuClient.Error.t()}

Executes an HTTP request with retry and rate limiting.

Returns {:ok, raw_response()} or {:error, %SetuClient.Error{}}.