Skir.RPC.ServiceClient (skir_elixir_client v0.2.2)

Copy Markdown View Source

HTTP client for unary SkirRPC methods.

Summary

Functions

Invokes a method and returns {:ok, response} or {:error, %Skir.RPC.RpcError{}}. Options include :headers, :http_method (:post or :get), and transport options.

Invokes a method, returning the decoded response or raising Skir.RPC.RpcError.

Creates an HTTP client, returning {:ok, client} or {:error, message}. Accepts :headers, :transport, and :transport_opts.

Creates an HTTP client or raises ArgumentError for an invalid URL or options.

Returns a client with the default header replaced case-insensitively, or added if absent.

Types

header()

@type header() :: {String.t(), String.t()}

http_method()

@type http_method() :: :get | :post

t()

@type t() :: %Skir.RPC.ServiceClient{
  headers: [header()],
  service_url: String.t(),
  transport: module() | function(),
  transport_opts: keyword()
}

Functions

invoke(client, method, request, opts \\ [])

@spec invoke(t(), Skir.Method.t(), term(), keyword()) ::
  {:ok, term()} | {:error, Skir.RPC.RpcError.t()}

Invokes a method and returns {:ok, response} or {:error, %Skir.RPC.RpcError{}}. Options include :headers, :http_method (:post or :get), and transport options.

invoke!(client, method, request, opts \\ [])

@spec invoke!(t(), Skir.Method.t(), term(), keyword()) :: term()

Invokes a method, returning the decoded response or raising Skir.RPC.RpcError.

new(service_url, opts \\ [])

@spec new(String.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

Creates an HTTP client, returning {:ok, client} or {:error, message}. Accepts :headers, :transport, and :transport_opts.

new!(service_url, opts \\ [])

@spec new!(String.t(), keyword()) :: t()

Creates an HTTP client or raises ArgumentError for an invalid URL or options.

with_default_header(client, key, value)

@spec with_default_header(t(), String.t(), String.t()) :: t()

Returns a client with the default header replaced case-insensitively, or added if absent.