Expand description
Unofficial, ergonomic Rust client for the Ably Chat REST API (v4).
Not affiliated with or endorsed by Ably.
§Overview
Build a Client with an Auth credential, scope it to a room with
Client::room, then chain into Messages, Reactions, or
OccupancyHandle. Each operation is a builder that terminates in a bare
.await (via IntoFuture); every fallible call
returns Result<T>. Handles are cheap to Clone (Arc-backed) and
Send + Sync.
History and versions are paginated: .await a query for the first
Page, or call .into_stream() to follow the next links to exhaustion.
§Example
use ably_chat::prelude::*;
use futures::StreamExt;
// Build a client and scope it to a room (rooms are implicit — this creates
// nothing server-side).
let client = Client::builder(Auth::api_key("appId.keyId:keySecret")).build();
let room = client.room("my-room");
// Send a message.
let sent = room.messages().send("hello, world").await?;
println!("sent message {}", sent.serial);
// Stream history (newest first by default), following pagination. The
// stream is `!Unpin`, so pin it before polling with `.next()`.
let mut history = std::pin::pin!(room.messages().history().into_stream());
while let Some(message) = history.next().await {
let message = message?;
println!("{}: {}", message.client_id, message.text);
}§Permissions & token issuance
Build the capability string for a TokenRequest or JWT with Capability
(feature capabilities), mint the JWT itself with mint_ably_jwt
(feature jwt; server-side only — it signs with your API secret),
and let the client refresh Bearer credentials automatically by building
Auth with Auth::provider instead of a static token (ADR-0012,
SPEC §13).
Prefer not to sign requests yourself? KeyTokenProvider (feature
token-issuance, off by default) mints Ably Tokens through the platform
requestToken endpoint instead — also server-side only. Pair it with
Auth::provider the same way (ADR-0012 item 5, SPEC §13).
Modules§
- prelude
- Convenience re-exports for common usage.
- raw
- Low-level generated bindings. Escape hatch; NOT covered by the pre-1.0 stability guarantee and may change on regeneration.
Structs§
- Capability
- A capability document: resource pattern → set of allowed operation strings.
Operation strings are stored (not the enum) so the
BTreeSetsorts lexicographically by wire value, matching Ably’s canonicalization. - Client
- The entry point to the Ably Chat REST API.
- Client
Builder - Builder for
Client. Requires credentials; host, timeout, retry budget, and a caller-suppliedreqwest::Clientare optional. - Client
IdCounts - Aggregated per-client counts for a
multiplereaction. - Client
IdList - Aggregated set of client IDs for a
unique/distinctreaction. - Client
Reactions - Builder for
Reactions::for_client;.awaitit to fetch aReactionSummary. Withoutclient_id, the server defaults to the authenticated caller’s client ID. - Delete
Message - Builder for
Messages::delete;.awaitit to soft-delete the message and receive the resultingMessage(actionmessage.delete). - Delete
Reaction - Builder for
Reactions::delete;.awaitit to remove the reaction. Resolves to()on success (the endpoint returns204with no body). - Error
Info - The Ably error envelope carried by a non-2xx API response.
- GetMessage
- Builder for
Messages::get;.awaitit to fetch aMessage. - GetOccupancy
- Builder for
OccupancyHandle::get;.awaitit to fetchOccupancy. - History
- Builder for
Messages::history..awaityields the firstPage<Message>;into_streamfollows all pages. - KeyToken
Provider - Mints Ably Tokens by calling
POST /keys/{keyName}/requestTokenwith an unsignedTokenParamsbody under HTTP Basic auth. Pair withAuth::providerfor automatic use + refresh. - Message
- A chat message in the V4 REST representation.
- Message
Version - Details of the latest create/update/delete version of a message.
- Messages
- Message operations for a room.
- Occupancy
- Occupancy metrics for a room.
- Occupancy
Handle - Occupancy operations for a room.
- Page
- One page of a paginated collection: the decoded items plus the parsed
rel="next"cursor (ADR-0009). - Reaction
Summary - Summary of reactions on a message, grouped by reaction type. Each map is keyed by the reaction name (e.g. an emoji). Absent groups default to empty.
- Reactions
- Reaction operations on messages in a room.
- Room
- A handle to a single chat room, scoped by
RoomName. - Room
Name - The name of a chat room.
- Send
Message - Builder for
Messages::send;.awaitit to publish the message and receive the createdMessage. - Send
Reaction - Builder for
Reactions::send;.awaitit to add the reaction. Resolves to()on success (the endpoint returns201with no body). - Serial
- A message’s unique, region-scoped identifier.
- Signing
Key - An Ably API key split into its name (
appId.keyId) and secret, for signing Ably JWTs.Debugredacts the secret. - Timestamp
- Milliseconds since the Unix epoch.
- Token
Params - Inputs for minting an Ably JWT.
capabilityis the capability JSON string (with thecapabilitiesfeature, produce it viaCapability::to_capability_string). - Update
Message - Builder for
Messages::update;.awaitit to apply the edit and receive the updatedMessage. - Versions
- Builder for
Messages::versions..awaityields the firstPage<Message>;into_streamfollows all pages.
Enums§
- Auth
- Static credentials supplied to the client.
- Direction
- History/versions ordering. Query-only; serialized as a lowercase string by the dispatch layer, never via serde.
- Error
- The single error type surfaced by this crate.
- Message
Action - The action that produced a message version.
- Operation
- An Ably capability operation.
#[non_exhaustive]; unknown wire values map toOther(ADR-0007) so parsing never fails. - Reaction
Type - The reaction aggregation model.
Traits§
- Token
Provider - Supplies a currently-valid Bearer credential (Ably Token string or Ably JWT),
refreshed on demand. The returned string is the raw token — the client adds
the
Bearerprefix. Implementations MUST be cheap to call when cached.
Functions§
- mint_
ably_ jwt - Mint an HS256 Ably JWT signed with the key secret. No network call.