ClearBank.HTTP (ClearBank v1.0.0)

Copy Markdown View Source

Core HTTP request pipeline for the ClearBank API.

Handles:

  • Authorization header injection
  • DigitalSignature computation for mutating requests
  • X-Request-Id generation (UUID v4) with optional override for retry safety
  • X-Correlation-Id capture from responses
  • Retry-After header parsing on 503
  • Telemetry events
  • Unified error mapping to ClearBank.Error

Retry safety

ClearBank requires retrying 5XX errors with the exact same X-Request-Id. Pass :request_id in opts to pin the ID across retry attempts:

stable_id = ClearBank.HTTP.generate_request_id()

ClearBank.HTTP.Retry.with_retry(fn ->
  ClearBank.HTTP.post(client, "/v3/Payments/FPS", body, request_id: stable_id)
end)

Summary

Functions

Performs a DELETE request.

Generates a UUID v4 string suitable for use as X-Request-Id.

Performs a GET request.

Types

method()

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

opts()

@type opts() :: keyword()

path()

@type path() :: String.t()

result()

@type result() :: {:ok, map() | list() | nil} | {:error, ClearBank.Error.t()}

Functions

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

@spec delete(ClearBank.Client.t(), path(), opts()) :: result()

Performs a DELETE request.

generate_request_id()

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

Generates a UUID v4 string suitable for use as X-Request-Id.

Pre-generate a stable ID when you need to retry a request with the same ID — ClearBank's idempotency requirement for 5XX retries.

Examples

id = ClearBank.HTTP.generate_request_id()
# => "550e8400-e29b-4d3f-a716-446655440000"

ClearBank.HTTP.Retry.with_retry(fn ->
  ClearBank.HTTP.post(client, "/v3/Payments/FPS", body, request_id: id)
end)

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

@spec get(ClearBank.Client.t(), path(), opts()) :: result()

Performs a GET request.

Options

  • :request_id - override the auto-generated X-Request-Id (for retry with same ID)

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

@spec patch(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()

Performs a PATCH request.

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

@spec post(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()

Performs a POST request.

Options

  • :request_id - pin X-Request-Id for idempotent retries

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

@spec put(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()

Performs a PUT request.