ProtoRune.HTTPClient (proto_rune v0.5.2)

Copy Markdown

The HTTPClient module handles HTTP requests to external services. It provides a simple interface for making GET and POST requests and handling responses.

Rate limiting and retries

Requests are transparently throttled and retried at the transport layer:

  • requests are tracked per host in one-minute windows; once the configured limit is reached the caller sleeps until the next window
  • responses with status 429 are retried with exponential backoff, honoring the Retry-After header when present

Configuration is read from the application environment:

config :proto_rune, :rate_limit,
  requests_per_minute: 3_000

config :proto_rune, :retry,
  max_attempts: 3,
  base_delay: 500,
  max_delay: 10_000

Both can also be given per request through the :rate_limit and :retry options of request/3, or disabled with false:

HTTPClient.request(:get, url, retry: [max_attempts: 1])
HTTPClient.request(:get, url, rate_limit: false)

Retry options:

  • :max_attempts - total attempts, including the first one (default 3)
  • :base_delay - backoff delay for the first retry in ms (default 500)
  • :max_delay - ceiling for the backoff delay in ms (default 10_000)
  • :sleep_fun - one-arity function used to wait between attempts, defaults to Process.sleep/1

Summary

Functions

request(method, url, opts \\ [])