Tinkex.API.Response (Tinkex v0.3.4)

View Source

Wrapper around HTTP responses with metadata and parsing helpers.

Summary

Functions

Retrieve a header value (case-insensitive).

Build a response wrapper from a Finch response.

Parse the response body using a module or function.

Types

t()

@type t() :: %Tinkex.API.Response{
  body: binary(),
  data: term() | nil,
  elapsed_ms: non_neg_integer(),
  headers: map(),
  method: atom(),
  retries: non_neg_integer(),
  status: integer(),
  url: String.t()
}

Functions

header(response, name)

@spec header(t(), String.t()) :: String.t() | nil

Retrieve a header value (case-insensitive).

new(response, opts)

@spec new(
  Finch.Response.t(),
  keyword()
) :: t()

Build a response wrapper from a Finch response.

parse(resp, parser \\ nil)

@spec parse(t(), module() | (term() -> term()) | nil) ::
  {:ok, term()} | {:error, term()}

Parse the response body using a module or function.

  • Module parser: must export from_json/1
  • Function parser: unary function that accepts the decoded JSON
  • nil parser: returns the decoded JSON map