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.
Types
pub type Client {
Client(
send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
String,
),
)
}
Constructors
-
Client( send: fn(request.Request(BitArray)) -> Result( response.Response(BitArray), String, ), )
pub type XrpcError {
RequestFailed(String)
BadStatus(
status: Int,
error: option.Option(String),
message: option.Option(String),
body: String,
)
DecodeFailed(String)
}
Constructors
-
RequestFailed(String) -
BadStatus( status: Int, error: option.Option(String), message: option.Option(String), body: String, )A non-2xx response. atproto error bodies are JSON
{error, message}; both are parsed out (when present) so callers can branch onerror(e.g.ExpiredToken) instead of string-matching the raw body. -
DecodeFailed(String)
Values
pub fn describe(error: 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), XrpcError)
pub fn get_bits(
client: Client,
url: String,
token: option.Option(String),
) -> Result(response.Response(BitArray), 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, XrpcError)
pub fn post_bits(
client: Client,
url: String,
token: option.Option(String),
body: BitArray,
content_type: String,
) -> Result(response.Response(String), 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), XrpcError)
pub fn send_text(
client: Client,
req: request.Request(String),
) -> Result(response.Response(String), String)
Send a text request and decode the response body as text. The seam between the string-shaped JSON world and the BitArray transport.