capnweb_client/lib.rs
1//! # Cap'n Web Client Library
2//!
3//! High-performance Rust client for the Cap'n Web RPC protocol.
4//!
5//! This crate provides a complete client implementation with support for:
6//! - Automatic request batching for optimal network usage
7//! - Promise pipelining to minimize round-trips
8//! - Type-safe capability references
9//! - Connection pooling and retry logic
10//!
11//! ## Quick Start
12//!
13//! ```rust,no_run
14//! use capnweb_client::{Client, ClientConfig};
15//! use capnweb_core::CapId;
16//! use serde_json::json;
17//!
18//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
19//! // Connect to a Cap'n Web server
20//! let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
21//!
22//! // Make a simple RPC call
23//! let result = client.call(
24//! CapId::new(1), // Capability ID
25//! "getData", // Method name
26//! vec![json!({"id": 42})] // Arguments
27//! ).await?;
28//!
29//! println!("Result: {}", result);
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! ## Batch Operations
35//!
36//! Batch multiple operations for efficient network usage:
37//!
38//! ```rust,no_run
39//! use capnweb_client::Client;
40//! use capnweb_core::CapId;
41//! use serde_json::json;
42//!
43//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
44//! # let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
45//! let mut batch = client.batch();
46//!
47//! // Queue multiple operations
48//! let user = batch.call(CapId::new(1), "getUser", vec![json!(123)]);
49//! let posts = batch.call(CapId::new(1), "getPosts", vec![json!(123)]);
50//!
51//! // Execute all at once
52//! let results = batch.execute().await?;
53//!
54//! // Access individual results
55//! let user_data = results.get(&user)?;
56//! let posts_data = results.get(&posts)?;
57//! # Ok(())
58//! # }
59//! ```
60//!
61//! ## Promise Pipelining
62//!
63//! Chain operations on unresolved promises to minimize latency:
64//!
65//! ```rust,no_run
66//! use capnweb_client::Client;
67//! use capnweb_core::CapId;
68//! use serde_json::json;
69//!
70//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
71//! # let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
72//! let mut batch = client.batch();
73//!
74//! // First call returns a user object
75//! let user = batch.call(CapId::new(1), "getUser", vec![json!(123)]);
76//!
77//! // Pipeline on the result without waiting
78//! let profile = batch.pipeline(
79//! &user, // Base result
80//! vec!["profile"], // Path to property
81//! "load", // Method to call
82//! vec![] // Arguments
83//! );
84//!
85//! let results = batch.execute().await?;
86//! # Ok(())
87//! # }
88//! ```
89
90pub mod client;
91#[cfg(feature = "macros")]
92pub mod macros;
93pub mod recorder;
94pub mod stubs;
95
96pub use client::{BatchBuilder, BatchResults, Client, ClientConfig, PendingResult};
97pub use recorder::{RecordedPlan, Recorder};
98pub use stubs::{Capability, StubError};