Quant.Explorer.HttpClient (quant v0.1.0-alpha.1)

HTTP client wrapper with retry logic, timeout handling, and standardized error responses.

This module provides a consistent interface for making HTTP requests across all providers, with built-in retry mechanisms and error handling.

Summary

Functions

Decodes JSON response body.

Extracts error message from HTTP response based on common API patterns.

Makes a GET request with optional query parameters.

Makes a POST request with a request body.

Makes a generic HTTP request with retry logic.

Checks if HTTP response indicates success (2xx status code).

Types

headers()

@type headers() :: [{String.t(), String.t()}]

options()

@type options() :: keyword()

params()

@type params() :: keyword() | map()

response()

@type response() ::
  {:ok, %{status: integer(), body: binary(), headers: headers()}}
  | {:error, term()}

url()

@type url() :: String.t()

Functions

decode_json(body)

@spec decode_json(binary()) :: {:ok, term()} | {:error, term()}

Decodes JSON response body.

Returns {:ok, decoded_data} or {:error, {:parse_error, reason}}.

extract_error_message(map)

@spec extract_error_message(map()) :: String.t()

Extracts error message from HTTP response based on common API patterns.

get(url, params \\ %{}, opts \\ [])

@spec get(url(), params(), options()) :: response()

Makes a GET request with optional query parameters.

Options

  • :timeout - Request timeout in milliseconds (default: 10000)
  • :retries - Number of retry attempts (default: 3)
  • :retry_delay - Delay between retries in milliseconds (default: 1000)
  • :headers - Additional HTTP headers
  • :follow_redirect - Whether to follow redirects (default: true)

post(url, body, opts \\ [])

@spec post(url(), binary(), options()) :: response()

Makes a POST request with a request body.

Options

Same as get/3, plus:

  • :content_type - Content-Type header (default: "application/json")

request(method, url, body, headers, opts)

@spec request(atom(), url(), binary(), headers(), options()) :: response()

Makes a generic HTTP request with retry logic.

success?(status)

@spec success?(integer()) :: boolean()

Checks if HTTP response indicates success (2xx status code).