1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # 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
//!
//! ```rust,no_run
//! use capnweb_client::{Client, ClientConfig};
//! use capnweb_core::CapId;
//! use serde_json::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // 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);
//! # Ok(())
//! # }
//! ```
//!
//! ## Batch Operations
//!
//! Batch multiple operations for efficient network usage:
//!
//! ```rust,no_run
//! use capnweb_client::Client;
//! use capnweb_core::CapId;
//! use serde_json::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
//! 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)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Promise Pipelining
//!
//! Chain operations on unresolved promises to minimize latency:
//!
//! ```rust,no_run
//! use capnweb_client::Client;
//! use capnweb_core::CapId;
//! use serde_json::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = Client::new_with_url("http://localhost:8080/rpc/batch")?;
//! 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?;
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use ;