atproto/browser/xrpc

Async transport-agnostic XRPC plumbing for the browser: the javascript-target mirror of atproto/xrpc.gleam, but every call returns a Promise since browser fetch is unavoidably async. atproto/xrpc.gleam’s Client type is honestly synchronous (satisfied by Erlang’s genuinely blocking httpc), and that contract can’t be honestly satisfied by real browser fetch, so this is a parallel client, not a drop-in replacement. Ships a ready-made fetch_client() sender built on gleam_fetch, so a caller doesn’t need to write their own. Error and transport vocabulary is shared with the sync client through atproto_core/xrpc, so both targets (and a generated sync or async client) speak one XrpcError/TransportError; constructing those variants (e.g. in a custom send) needs that import.

Types

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

Constructors

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

Values

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

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

pub fn fetch_client() -> Client

A Client backed by real browser fetch.

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

GET returning the raw bytes (e.g. blob or image downloads).

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,
) -> promise.Promise(
  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,
) -> promise.Promise(
  Result(response.Response(String), xrpc.XrpcError),
)
pub fn send_text(
  client: Client,
  req: request.Request(String),
) -> promise.Promise(
  Result(response.Response(String), xrpc.TransportError),
)
pub fn transport_error_to_string(
  error: xrpc.TransportError,
) -> String

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

Search Document