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.
Performs a PATCH request.
Performs a POST request.
Performs a PUT request.
Types
@type method() :: :get | :post | :put | :patch | :delete
@type opts() :: keyword()
@type path() :: String.t()
@type result() :: {:ok, map() | list() | nil} | {:error, ClearBank.Error.t()}
Functions
@spec delete(ClearBank.Client.t(), path(), opts()) :: result()
Performs a DELETE request.
@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)
@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)
@spec patch(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()
Performs a PATCH request.
@spec post(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()
Performs a POST request.
Options
:request_id- pin X-Request-Id for idempotent retries
@spec put(ClearBank.Client.t(), path(), body :: map(), opts()) :: result()
Performs a PUT request.