atproto/xrpc

Transport-agnostic XRPC plumbing. The Client wraps a send function so the caller chooses the HTTP backend (erlang httpc, JS fetch, a test stub), keeping this module free of any target-specific dependency. Bodies are BitArrays so blobs ride the same client; the text helpers below keep JSON call sites string-shaped.

TransportError/XrpcError alias atproto_core/xrpc’s types; constructing their variants (e.g. in a custom send) needs that import.

Types

pub type Client {
  Client(
    send: fn(request.Request(BitArray)) -> Result(
      response.Response(BitArray),
      xrpc.TransportError,
    ),
  )
}

Constructors

pub type TransportError =
  xrpc.TransportError
pub type XrpcError =
  xrpc.XrpcError

Values

pub fn check_ok(
  resp: response.Response(String),
) -> Result(response.Response(String), xrpc.XrpcError)

Turn a received response into a Result: Ok on 2xx, else a BadStatus with the atproto error/message parsed out of the body when present.

pub fn describe(error: xrpc.XrpcError) -> String

A one-line human-readable rendering of an error, for CLI and log output.

pub fn get(
  client: Client,
  url: String,
  token: option.Option(String),
) -> Result(response.Response(String), xrpc.XrpcError)
pub fn get_bits(
  client: Client,
  url: String,
  token: option.Option(String),
) -> Result(response.Response(BitArray), xrpc.XrpcError)

GET returning the raw bytes (e.g. blob or image downloads). The error body on a bad status is decoded leniently for the message.

pub fn parse(
  body: String,
  decoder: decode.Decoder(a),
) -> Result(a, xrpc.XrpcError)
pub fn post_bits(
  client: Client,
  url: String,
  token: option.Option(String),
  body: BitArray,
  content_type: String,
) -> Result(response.Response(String), xrpc.XrpcError)

POST raw bytes (e.g. uploadBlob); the response is decoded as text (JSON).

pub fn post_json(
  client: Client,
  url: String,
  token: option.Option(String),
  body: json.Json,
) -> Result(response.Response(String), xrpc.XrpcError)
pub fn send_text(
  client: Client,
  req: request.Request(String),
) -> Result(response.Response(String), xrpc.TransportError)

Send a text request and decode the response body as text. The seam between the string-shaped JSON world and the BitArray transport.

pub fn transport_error_to_string(
  error: xrpc.TransportError,
) -> String

A one-line human-readable rendering of a transport error.

Search Document