Layr8.REST (layr8 v0.2.11)

Copy Markdown View Source

Internal HTTP client for the Layr8 cloud-node REST API.

Uses Req for HTTP requests. Authentication is via x-api-key header.

Not intended for direct use; accessed through Layr8.Credentials and Layr8.Presentations.

Summary

Functions

Issues a GET request to path and returns the decoded response.

Creates a new REST client.

Issues a JSON POST request to path with body and returns the decoded response.

Types

t()

@type t() :: %Layr8.REST{
  api_key: String.t(),
  base_url: String.t(),
  timeout_ms: non_neg_integer()
}

Functions

get(client, path, opts \\ [])

@spec get(t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}

Issues a GET request to path and returns the decoded response.

Options

  • :timeout_ms — deadline on the response. 0 or nil leaves the call unbounded, which is the pre-existing behaviour.

Returns {:ok, map()} on success or {:error, term()} on failure.

new(base_url, api_key, opts \\ [])

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

Creates a new REST client.

Parameters

  • base_url — HTTP base URL of the cloud-node (e.g. "https://node.example.com")
  • api_key — API key for authentication

Options

  • :timeout_ms — default deadline on every call made through this client. 0 leaves them unbounded. See Layr8.Config.default_rest_timeout_ms/0 for why the default is a deadline at all: Req has none of its own, so a node that accepted the connection and went quiet left every credential and presentation call hanging — neither resolving nor failing, and never letting the caller reach the point of deciding to retry.

post(client, path, body, opts \\ [])

@spec post(t(), String.t(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Issues a JSON POST request to path with body and returns the decoded response.

Options

  • :timeout_ms — deadline on the response. 0 or nil leaves the call unbounded, which is the pre-existing behaviour.

Returns {:ok, map()} on success or {:error, term()} on failure.