Expand description
§Cap’n Web Client Library
High-performance Rust client for the Cap’n Web RPC protocol.
This crate provides a complete client implementation with support for:
- Automatic request batching for optimal network usage
- Promise pipelining to minimize round-trips
- Type-safe capability references
- Connection pooling and retry logic
§Quick Start
use capnweb_client::{Client, ClientConfig};
use capnweb_core::CapId;
use serde_json::json;
// Connect to a Cap'n Web server
let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
// Make a simple RPC call
let result = client.call(
CapId::new(1), // Capability ID
"getData", // Method name
vec![json!({"id": 42})] // Arguments
).await?;
println!("Result: {}", result);§Batch Operations
Batch multiple operations for efficient network usage:
use capnweb_client::Client;
use capnweb_core::CapId;
use serde_json::json;
let mut batch = client.batch();
// Queue multiple operations
let user = batch.call(CapId::new(1), "getUser", vec![json!(123)]);
let posts = batch.call(CapId::new(1), "getPosts", vec![json!(123)]);
// Execute all at once
let results = batch.execute().await?;
// Access individual results
let user_data = results.get(&user)?;
let posts_data = results.get(&posts)?;§Promise Pipelining
Chain operations on unresolved promises to minimize latency:
use capnweb_client::Client;
use capnweb_core::CapId;
use serde_json::json;
let mut batch = client.batch();
// First call returns a user object
let user = batch.call(CapId::new(1), "getUser", vec![json!(123)]);
// Pipeline on the result without waiting
let profile = batch.pipeline(
&user, // Base result
vec!["profile"], // Path to property
"load", // Method to call
vec![] // Arguments
);
let results = batch.execute().await?;Re-exports§
pub use client::BatchBuilder;pub use client::BatchResults;pub use client::Client;pub use client::ClientConfig;pub use client::PendingResult;pub use recorder::RecordedPlan;pub use recorder::Recorder;pub use stubs::Capability;pub use stubs::StubError;
Modules§
Macros§
- params
- Macro for creating parameter sources with less boilerplate
- record_
array - Macro for array construction with natural syntax
- record_
object - Macro for object construction with natural syntax
- record_
plan - Macro for creating recorded plans with fluent syntax