PaveDBClient.Client (pavedb_client v0.1.0)

Copy Markdown

HTTP transport for PaveDB.

Summary

Types

t()

Replacement HTTP sender, called as transport.(method, path, headers, body).

Functions

Builds a client struct. Prefer PaveDBClient.connect/2, which fills the base URL in from PAVEDB_URL.

Sends a request with an empty body and decodes the response envelope.

Sends a request with body and decodes the response envelope.

Sends body as JSON and decodes the response envelope.

Sends a request and returns the undecoded response body on success.

Types

t()

@type t() :: %PaveDBClient.Client{
  base_url: String.t(),
  connect_timeout: timeout(),
  headers: [{String.t(), String.t()}],
  tenant: String.t(),
  timeout: timeout(),
  token: String.t() | nil,
  transport: transport() | nil
}

transport()

@type transport() :: (atom(), String.t(), [{String.t(), String.t()}], binary() ->
                  {:ok, non_neg_integer(), list(), binary()} | {:error, term()})

Replacement HTTP sender, called as transport.(method, path, headers, body).

Functions

new(base_url, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Builds a client struct. Prefer PaveDBClient.connect/2, which fills the base URL in from PAVEDB_URL.

Takes :tenant, :token (or :api_key), :headers, :timeout, :connect_timeout, and :transport. A base URL already ending in /v1 is used as-is.

request(client, method, path, opts \\ [])

@spec request(t(), atom(), String.t(), keyword()) ::
  {:ok, map()} | {:error, PaveDBClient.Error.t()}

Sends a request with an empty body and decodes the response envelope.

Pass root: true for endpoints outside the /v1 API, such as /health.

request(client, method, path, body, opts)

@spec request(t(), atom(), String.t(), iodata(), keyword()) ::
  {:ok, map()} | {:error, PaveDBClient.Error.t()}

Sends a request with body and decodes the response envelope.

Takes :content_type and :root.

request_json(client, method, path, body)

@spec request_json(t(), atom(), String.t(), map()) ::
  {:ok, map()} | {:error, PaveDBClient.Error.t()}

Sends body as JSON and decodes the response envelope.

request_raw(client, method, path, opts \\ [])

@spec request_raw(t(), atom(), String.t(), keyword()) ::
  {:ok, map()} | {:error, PaveDBClient.Error.t()}

Sends a request and returns the undecoded response body on success.

Used for endpoints that answer with a raw body (for example chunk content) instead of the usual JSON envelope. Non-2xx responses still decode into a structured Error.