Expand description
§Convex Client
The official Rust client for Convex.
Convex is the backend application platform with everything you need to build your product. Convex clients can subscribe to queries and perform mutations and actions. Check out the Convex Documentation for more information.
§Usage
§Native Rust development
To use Convex to create native Rust applications with tokio
, you can use
the ConvexClient
struct directly. All you need is your deployment URL
from your existing project, and you can subscribe to queries and call
mutations. To make a new project, check out our getting started guide.
use convex::ConvexClient;
use futures::StreamExt;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut client = ConvexClient::new("https://cool-music-123.convex.cloud").await?;
client.mutation("sendMessage", maplit::btreemap!{
"body".into() => "Let it be.".into(),
"author".into() => "The Beatles".into(),
}).await?;
let mut sub = client.subscribe("listMessages", maplit::btreemap!{}).await?;
while let Some(result) = sub.next().await {
println!("{result:?}");
}
Ok(())
}
§Extending client for other programming languages or frameworks.
To extend Convex into non-tokio
frameworks,
you can use the base_client::BaseConvexClient
to build something similar
to a ConvexClient
.
Detailed examples of both use cases are documented for each struct.
Modules§
- base_
client - The synchronous state machine for Convex. It’s
recommended to use the higher level
ConvexClient
unless you are building a framework.
Macros§
- convex_
logs - Macro used for piping UDF logs to a custom formatter that exposes just the log content, without any additional Rust metadata.
Structs§
- Convex
Client - An asynchronous client to interact with a specific project to perform
mutations and manage query subscriptions using
tokio
. - Convex
Client Builder - A builder for creating a
ConvexClient
with custom configuration. - Convex
Error - An application error that can be returned from Convex functions. To learn more about throwing custom application errors, see Convex Errors.
- Query
Results - A mapping from
SubscriberId
to its current resultFunctionResult
for each actively subscribed query. - Query
SetSubscription - A subscription to a consistent view of multiple queries.
- Query
Subscription - This structure represents a single subscription to a query with args.
For convenience,
QuerySubscription
also implementsStream
<FunctionResult
>, giving a stream of results to the query. - Subscriber
Id - An identifier for a single subscriber to a query.
Enums§
- Function
Result - Result of a Convex function (query/mutation/action).
- Value
- A value that can be passed as an argument or returned from Convex functions. They correspond to the supported Convex types.
- WebSocket
State - The state of the Convex WebSocket connection