Exth.Transport.Http (Exth v0.2.1)
View SourceHTTP 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
Functions
Makes an HTTP request to the JSON-RPC endpoint.
Creates a new HTTP transport with the given options.
Types
@type t() :: %Exth.Transport.Http{client: Tesla.Client.t()}
HTTP transport configuration
Functions
@spec call(t(), Exth.Rpc.Request.t() | [Exth.Rpc.Request.t()]) :: {:ok, Exth.Rpc.Response.t() | [Exth.Rpc.Response.t()]} | {:error, term()}
Makes an HTTP request to the JSON-RPC endpoint.
Returns:
{:ok, responses}
- Successful request with decoded response or responses{:error, {:http_error, status}}
- HTTP error response{:error, reason}
- Other errors (network, timeout, etc)
Creates a new HTTP transport with the given options.
Options
:rpc_url
- (required) The HTTP/HTTPS endpoint URL:encoder
- (required) Function to encode requests:decoder
- (required) Function to decode responses:adapter
- Tesla adapter to use (defaults toTesla.Adapter.Mint
):headers
- Additional HTTP headers for requests:timeout
- Request timeout in milliseconds (defaults to 30000)