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. Transport failures use atproto_core/xrpc.TransportError
from atproto_client, so both targets share one error vocabulary.
Types
pub type Client {
Client(
send: fn(request.Request(BitArray)) -> promise.Promise(
Result(response.Response(BitArray), xrpc.TransportError),
),
)
}
Constructors
-
Client( send: fn(request.Request(BitArray)) -> promise.Promise( Result(response.Response(BitArray), xrpc.TransportError), ), )
pub type XrpcError {
RequestFailed(xrpc.TransportError)
BadStatus(
status: Int,
error: option.Option(String),
message: option.Option(String),
body: String,
)
DecodeFailed(String)
}
Constructors
-
RequestFailed(xrpc.TransportError) -
BadStatus( status: Int, error: option.Option(String), message: option.Option(String), body: String, ) -
DecodeFailed(String)
Values
pub fn get(
client: Client,
url: String,
token: option.Option(String),
) -> promise.Promise(Result(response.Response(String), XrpcError))
pub fn get_bits(
client: Client,
url: String,
token: option.Option(String),
) -> promise.Promise(
Result(response.Response(BitArray), XrpcError),
)
GET returning the raw bytes (e.g. blob or image downloads).
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,
) -> promise.Promise(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,
) -> promise.Promise(Result(response.Response(String), XrpcError))
pub fn send_text(
client: Client,
req: request.Request(String),
) -> promise.Promise(
Result(response.Response(String), xrpc.TransportError),
)