Rapyd.HTTP.Behaviour behaviour (rapyd v1.0.0)

Copy Markdown View Source

Contract that every HTTP client implementation must satisfy.

In production, Rapyd.HTTP.Client fulfills this contract. In tests, a Mox mock can be injected via the http_client: option on Rapyd.new/1:

Mox.defmock(MockHTTP, for: Rapyd.HTTP.Behaviour)

client = Rapyd.new!(
  access_key: "key",
  secret_key: "secret",
  http_client: MockHTTP
)

Summary

Callbacks

Execute a signed HTTP request against the Rapyd API.

Callbacks

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

@callback request(
  client :: Rapyd.Client.t(),
  method :: :get | :post | :put | :patch | :delete,
  path :: String.t(),
  body :: map() | list() | nil,
  opts :: keyword()
) :: {:ok, term()} | {:error, Rapyd.Error.t()}

Execute a signed HTTP request against the Rapyd API.

  • client%Rapyd.Client{} carrying credentials and config
  • method:get | :post | :put | :patch | :delete

  • path — API path starting with /, e.g. "/v1/payments"
  • body — JSON-serialisable map / list, or nil for bodyless requests
  • opts — reserved for future use; pass []

Returns {:ok, data} where data is the decoded "data" field from the Rapyd envelope, or {:error, %Rapyd.Error{}}.