Http (fnord v0.8.82)

View Source

Summary

Functions

Sends a GET request to the specified URL with the given headers and query parameters. Returns a tuple with the response status and body, or an error if the request fails.

Sends a POST request with a JSON payload to the specified URL with the given headers. Returns a tuple with the response status and body, or an error if the request fails.

Types

get_response()

@type get_response() :: {:ok, String.t()} | http_error() | transport_error()

header()

@type header() :: {String.t(), String.t()}

headers()

@type headers() :: [header()]

http_error()

@type http_error() :: {:http_error, {http_status(), String.t()}}

http_status()

@type http_status() :: integer()

options()

@type options() :: keyword()

payload()

@type payload() :: map()

post_response()

@type post_response() :: success() | http_error() | transport_error()

query()

@type query() :: map() | String.t() | nil

success()

@type success() :: {:ok, map()}

transport_error()

@type transport_error() :: {:transport_error, any()}

url()

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

Functions

get(url, headers \\ [], query \\ nil)

@spec get(url(), headers(), query()) :: get_response()

Sends a GET request to the specified URL with the given headers and query parameters. Returns a tuple with the response status and body, or an error if the request fails.

Retries up to 10 times on 5xx HTTP responses and on select transient transport errors using exponential backoff with jitter.

post_json(url, headers, payload)

@spec post_json(url(), headers(), payload()) :: post_response()

Sends a POST request with a JSON payload to the specified URL with the given headers. Returns a tuple with the response status and body, or an error if the request fails.

Retries up to 10 times on 5xx HTTP responses and on select transient transport errors using exponential backoff with jitter.