XRPC HTTP client for Exosphere.ATProto.
XRPC is the HTTP API layer for Exosphere.ATProto. It provides:
- Queries (GET requests) for reading data
- Procedures (POST requests) for mutations
Examples
# Create a client for a PDS
client = Exosphere.ATProto.XRPC.Client.new("https://bsky.social")
# Make an unauthenticated query
{:ok, response} = Exosphere.ATProto.XRPC.Client.query(client, "com.atproto.identity.resolveHandle",
handle: "atproto.com"
)
# Make an authenticated procedure
client = Exosphere.ATProto.XRPC.Client.new("https://bsky.social", access_token: "...")
{:ok, response} = Exosphere.ATProto.XRPC.Client.procedure(client, "com.atproto.repo.createRecord",
repo: "did:plc:...",
collection: "app.bsky.feed.post",
record: %{text: "Hello!"}
)
Summary
Functions
Create a session (login).
Describe a repository.
Get a record from a repository.
List records from a repository.
Create a new XRPC client.
Make an XRPC procedure (HTTP POST).
Make an XRPC query (HTTP GET).
Refresh a session using the refresh token.
Upload a blob to the PDS.
Set the access token on a client.
Types
@type error() :: Exosphere.ATProto.XRPC.Error.t() | term()
@type procedure_body() :: map()
@type t() :: %Exosphere.ATProto.XRPC.Client{ access_token: String.t() | nil, base_url: String.t(), http: module() | nil, refresh_token: String.t() | nil, timeout: pos_integer() | nil }
Functions
Create a session (login).
Examples
{:ok, session} = Exosphere.ATProto.XRPC.Client.create_session(client, "user@example.com", "password")
client = Exosphere.ATProto.XRPC.Client.with_token(client, session["accessJwt"])
Describe a repository.
Examples
{:ok, info} = Exosphere.ATProto.XRPC.Client.describe_repo(client, "did:plc:...")
Get a record from a repository.
Examples
{:ok, record} = Exosphere.ATProto.XRPC.Client.get_record(client,
repo: "did:plc:...",
collection: "app.bsky.feed.post",
rkey: "3jui7kd2lry2e"
)
List records from a repository.
Examples
{:ok, %{"records" => records}} = Exosphere.ATProto.XRPC.Client.list_records(client,
repo: "did:plc:...",
collection: "app.bsky.feed.post",
limit: 50
)
Create a new XRPC client.
Options
:access_token- JWT access token for authentication:refresh_token- JWT refresh token:timeout- Request timeout in milliseconds (default: 30_000)
Examples
# Unauthenticated client
client = Exosphere.ATProto.XRPC.Client.new("https://bsky.social")
# Authenticated client
client = Exosphere.ATProto.XRPC.Client.new("https://bsky.social",
access_token: "eyJ...",
refresh_token: "eyJ..."
)
@spec procedure(t(), String.t(), procedure_body() | keyword(), query_params()) :: {:ok, Exosphere.ATProto.HTTP.json_term()} | {:error, error()}
Make an XRPC procedure (HTTP POST).
Procedures are for mutations and may not be idempotent.
Examples
{:ok, %{"uri" => "at://...", "cid" => "bafyrei..."}} =
Exosphere.ATProto.XRPC.Client.procedure(client, "com.atproto.repo.createRecord",
repo: "did:plc:...",
collection: "app.bsky.feed.post",
record: %{"$type" => "app.bsky.feed.post", "text" => "Hello!"}
)
@spec query(t(), String.t(), query_params()) :: {:ok, Exosphere.ATProto.HTTP.json_term()} | {:error, error()}
Make an XRPC query (HTTP GET).
Queries are for reading data and are idempotent.
Examples
{:ok, %{"did" => "did:plc:..."}} =
Exosphere.ATProto.XRPC.Client.query(client, "com.atproto.identity.resolveHandle",
handle: "atproto.com"
)
Refresh a session using the refresh token.
Returns {:error, :no_refresh_token} when the client has no refresh token.
Upload a blob to the PDS.
Examples
{:ok, %{"blob" => blob}} =
Exosphere.ATProto.XRPC.Client.upload_blob(client, image_bytes, "image/jpeg")
Set the access token on a client.