Exth.Transport.Http (Exth v0.4.2)

View Source

HTTP transport implementation for JSON-RPC requests using Tesla.

Implements the Exth.Transport.Transportable protocol for making HTTP/HTTPS requests to JSON-RPC endpoints. Uses Tesla as the HTTP client with Mint as the default adapter.

Usage

transport = Transportable.new(
  %Exth.Transport.Http{},
  rpc_url: "https://mainnet.infura.io/v3/YOUR-PROJECT-ID",
)

{:ok, response} = Transportable.call(transport, request)

Summary

Types

t()

HTTP transport configuration

Functions

Makes an HTTP request to the JSON-RPC endpoint.

Creates a new HTTP transport with the given options.

Types

t()

@type t() :: %Exth.Transport.Http{client: Tesla.Client.t()}

HTTP transport configuration

Functions

call(http, request)

@spec call(t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Makes an HTTP request to the JSON-RPC endpoint.

Returns:

  • {:ok, response} - Successful request with encoded response
  • {:error, {:http_error, status}} - HTTP error response
  • {:error, reason} - Other errors (network, timeout, etc)

new(opts)

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

Creates a new HTTP transport with the given options.

Options

  • :rpc_url - (required) The HTTP/HTTPS endpoint URL
  • :adapter - Tesla adapter to use (defaults to Tesla.Adapter.Mint)
  • :headers - Additional HTTP headers for requests
  • :timeout - Request timeout in milliseconds (defaults to 30000)