Arcanum.HTTP (arcanum v0.1.8)

Copy Markdown View Source

Shared HTTP utilities for Arcanum adapters.

Centralizes the configurable HTTP client, URL construction, and async response body draining.

Summary

Functions

Builds a full URL from a provider's base_url and a path.

Builds a full URL from a provider's base_url and a path, also stripping a trailing /v1 segment. Used by Anthropic which appends its own /v1/messages path.

Returns the configured HTTP client module (defaults to Req).

Drains a Req.Response.Async body into a decoded map or raw binary.

Functions

base_url(provider, path)

@spec base_url(map(), String.t()) :: String.t()

Builds a full URL from a provider's base_url and a path.

Trims trailing / from the base URL before appending.

base_url_strip_v1(provider, path)

@spec base_url_strip_v1(map(), String.t()) :: String.t()

Builds a full URL from a provider's base_url and a path, also stripping a trailing /v1 segment. Used by Anthropic which appends its own /v1/messages path.

client()

@spec client() :: module()

Returns the configured HTTP client module (defaults to Req).

drain_async_body(async)

@spec drain_async_body(term()) :: term()

Drains a Req.Response.Async body into a decoded map or raw binary.

Enforces a 10 MB byte limit to prevent unbounded memory consumption. Returns nil on any error.

Passes non-async bodies through unchanged.