LatticeStripe.Transport.Finch (LatticeStripe v0.2.0)

Copy Markdown View Source

Default HTTP transport using Finch.

Translates the LatticeStripe.Transport contract into Finch.build/5 and Finch.request/3 calls.

Prerequisites

Add Finch to your supervision tree:

children = [
  {Finch, name: MyApp.Finch}
]

Then pass the pool name to your client:

LatticeStripe.Client.new!(api_key: "sk_test_...", finch: MyApp.Finch)

Summary

Functions

Executes an HTTP request using Finch.

Functions

request(map)

Executes an HTTP request using Finch.

This is the default LatticeStripe.Transport implementation. It translates the transport request map into a Finch.build/4 call, then dispatches via Finch.request/3.

Parameters

  • request_map - A map with keys:
    • method - HTTP method atom (:get, :post, :delete)
    • url - Full URL string (e.g., "https://api.stripe.com/v1/customers")
    • headers - List of {name, value} string tuples
    • body - Request body string or nil (for GET requests)
    • opts - Keyword list that must include:
      • :finch - Name atom of a running Finch pool (required)
      • :timeout - Receive timeout in milliseconds (default: 30_000)

Returns

  • {:ok, %{status: integer, headers: list, body: binary}} on success
  • {:error, exception} on network failure (e.g., connection refused, timeout)

Example

LatticeStripe.Transport.Finch.request(%{
  method: :get,
  url: "https://api.stripe.com/v1/customers/cus_123",
  headers: [{"authorization", "Bearer sk_test_..."}],
  body: nil,
  opts: [finch: MyApp.Finch, timeout: 30_000]
})
# => {:ok, %{status: 200, headers: [...], body: "{\"id\":\"cus_123\",...}"}}