Exosphere.ATProto.HTTP (Exosphere v0.2.0)

Copy Markdown View Source

Simple HTTP client using Mint.

Provides a high-level API for making HTTP requests using Mint under the hood. Each request opens a new connection (suitable for infrequent requests to many different hosts, as is common in Exosphere.ATProto).

Examples

{:ok, response} = Exosphere.ATProto.HTTP.get("https://plc.directory/did:plc:abc")
{:ok, response} = Exosphere.ATProto.HTTP.post("https://pds.example.com/xrpc/...", json: %{})

Summary

Functions

Make an HTTP GET request.

Make an HTTP POST request.

Make a generic HTTP request.

Types

json_term()

@type json_term() ::
  nil
  | boolean()
  | number()
  | binary()
  | [json_term()]
  | %{optional(binary()) => json_term()}

request_opts()

@type request_opts() :: [
  timeout: pos_integer(),
  headers: [{String.t(), String.t()}],
  json: map(),
  body: binary()
]

response()

@type response() :: %{
  status: pos_integer(),
  headers: [{String.t(), String.t()}],
  body: binary() | json_term()
}

Functions

get(url, opts \\ [])

@spec get(String.t(), request_opts()) :: {:ok, response()} | {:error, term()}

Make an HTTP GET request.

Options

  • :timeout - Request timeout in milliseconds (default: 30_000)
  • :headers - Additional headers to send

post(url, opts \\ [])

@spec post(String.t(), request_opts()) :: {:ok, response()} | {:error, term()}

Make an HTTP POST request.

Options

  • :timeout - Request timeout in milliseconds (default: 30_000)
  • :headers - Additional headers to send
  • :json - Map to encode as JSON body
  • :body - Raw binary body

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

@spec request(atom(), String.t(), request_opts()) ::
  {:ok, response()} | {:error, term()}

Make a generic HTTP request.