Unit.Client (Unit v1.0.0)

Copy Markdown View Source

Low-level HTTP client for the Unit API.

Handles:

  • JSON:API envelope building and parsing
  • Bearer token authentication
  • Automatic retries with exponential back-off (configurable)
  • Idempotency key injection
  • Telemetry instrumentation
  • Pagination helpers

You should not need to use this module directly. Prefer the high-level API modules (Unit.API.*).

Summary

Functions

Builds a query string for paginated list requests.

Performs a DELETE request.

Performs a GET request.

Generates a random idempotency key.

Performs a PATCH request.

Performs a POST request.

Performs a PUT request (used for binary uploads, e.g. document images).

Types

method()

@type method() :: :get | :post | :patch | :put | :delete

response()

@type response() :: {:ok, map() | [map()] | nil} | {:error, Unit.Error.t()}

Functions

build_query(opts)

@spec build_query(keyword()) :: String.t()

Builds a query string for paginated list requests.

Options

  • :page_limit — number of items per page (default: 100, max: 1000)
  • :page_offset — offset for cursor-based paging
  • :filter — map of filter params, e.g. %{status: "Active"}
  • :sort — sort field, e.g. "-createdAt" (prefix - for descending)
  • :include — comma-separated relationships to sideload

delete(path, opts \\ [])

@spec delete(
  String.t(),
  keyword()
) :: response()

Performs a DELETE request.

get(path, opts \\ [])

@spec get(
  String.t(),
  keyword()
) :: response()

Performs a GET request.

idempotency_key()

@spec idempotency_key() :: String.t()

Generates a random idempotency key.

Use the same key to safely retry mutating requests without double-processing.

patch(path, body \\ %{}, opts \\ [])

@spec patch(String.t(), map(), keyword()) :: response()

Performs a PATCH request.

post(path, body \\ %{}, opts \\ [])

@spec post(String.t(), map() | binary(), keyword()) :: response()

Performs a POST request.

put(path, body \\ %{}, opts \\ [])

@spec put(String.t(), binary() | map(), keyword()) :: response()

Performs a PUT request (used for binary uploads, e.g. document images).