Lithic.Client (Lithic v1.0.0)

Copy Markdown View Source

HTTP client for the Lithic API, built on Req.

Handles:

  • API key authentication
  • JSON encode/decode
  • Automatic retries with exponential backoff (5xx + network errors)
  • Telemetry events
  • Idempotency keys for mutating requests
  • Cursor-based pagination via Lithic.Page

Creating a client

# Uses application config
client = Lithic.Client.new()

# Override per-client
client = Lithic.Client.new(api_key: "my_key", environment: :sandbox)

Direct use (most users call resource modules instead)

{:ok, body} = Lithic.Client.get(client, "/cards")
{:ok, body} = Lithic.Client.post(client, "/cards", %{type: "VIRTUAL"})

Summary

Types

t()

@type t() :: %Lithic.Client{config: Lithic.Config.t(), req: Req.Request.t()}

Functions

delete(client, path, opts \\ [])

@spec delete(t(), String.t(), keyword()) :: {:ok, map()} | {:error, Lithic.Error.t()}

DELETE request.

get(client, path, opts \\ [])

@spec get(t(), String.t(), keyword()) :: {:ok, map()} | {:error, Lithic.Error.t()}

GET request.

new(opts \\ [])

@spec new(keyword()) :: t()

Build a new client. Accepts any Lithic.Config.resolve/1 override keys.

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

@spec patch(t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, Lithic.Error.t()}

PATCH request.

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

@spec post(t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, Lithic.Error.t()}

POST request.

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

@spec put(t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, Lithic.Error.t()}

PUT request.