BowlineClient.Transport (bowline_client v1.2.0)

Copy Markdown View Source

Sends procedure calls to a Bowline handler over HTTP and maps every outcome to {:ok, value} or {:error, %BowlineClient.Error{}}.

Queries go out as GET with the input in the input query parameter; mutations and sensitive queries go out as POST with a JSON body. A procedure mounted on a custom path uses rest/6, which spreads the input over individual query parameters when the method carries no body.

Summary

Functions

Calls a query or mutation and decodes the output with decode.

Builds a transport for the API served at base_url.

Calls a procedure mounted on a custom path.

Opens a subscription and returns a lazy stream of decoded messages.

Sends an upload: the JSON input as the first multipart part and the file as the second.

Types

call_opts()

@type call_opts() :: [
  headers: %{optional(String.t()) => String.t()},
  timeout: pos_integer()
]

decoder()

@type decoder() :: (term() -> term())

headers()

@type headers() ::
  %{optional(String.t()) => String.t()}
  | (-> %{optional(String.t()) => String.t()})

method()

@type method() :: :get | :post | :put | :patch | :delete

t()

@type t() :: %BowlineClient.Transport{
  base_url: String.t(),
  headers: headers(),
  req: Req.Request.t()
}

Functions

call(transport, path, method, input, decode, opts \\ [])

@spec call(t(), String.t(), method(), map(), decoder(), call_opts()) ::
  {:ok, term()} | {:error, BowlineClient.Error.t()}

Calls a query or mutation and decodes the output with decode.

new(opts)

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

Builds a transport for the API served at base_url.

Options: :headers as a map or a zero-arity function evaluated per call, and :req as extra options for Req.new/1.

rest(transport, path, method, input, decode, opts \\ [])

@spec rest(t(), String.t(), method(), map(), decoder(), call_opts()) ::
  {:ok, term()} | {:error, BowlineClient.Error.t()}

Calls a procedure mounted on a custom path.

A method that carries no body sends the input as individual query parameters rather than as a single input parameter.

subscribe(transport, path, input, decode, opts \\ [])

@spec subscribe(t(), String.t(), map(), decoder(), call_opts()) ::
  {:ok, Enumerable.t()} | {:error, BowlineClient.Error.t()}

Opens a subscription and returns a lazy stream of decoded messages.

upload(transport, path, input, file, filename, decode, opts \\ [])

@spec upload(
  t(),
  String.t(),
  map(),
  Enumerable.t() | binary(),
  String.t(),
  decoder(),
  call_opts()
) :: {:ok, term()} | {:error, BowlineClient.Error.t()}

Sends an upload: the JSON input as the first multipart part and the file as the second.