Tech News
← Back to articles

Show HN: Cap'n-rs – Rust implementation of Cloudflare's Cap'n Web protocol

read original related products more articles

Cap'n Web Rust Implementation

A complete, production-ready implementation of the Cap'n Web protocol in Rust, providing capability-based RPC with promise pipelining and multi-transport support.

Features

✅ Full Protocol Compliance - Implements the complete Cap'n Web wire protocol 🔒 Capability-Based Security - Unforgeable capability references with automatic lifecycle management 🚀 Promise Pipelining - Reduced round-trips through dependency resolution 🌐 Multi-Transport - HTTP batch, WebSocket, and WebTransport support 🛡️ Production-Ready - Zero-panic code, comprehensive error handling with context ✅ IL Expression Evaluation - Complete intermediate language support with array notation 🌍 JavaScript Interop - Validated against official TypeScript implementation

Quick Start

Add to Cargo.toml

[ dependencies ] capnweb-server = " 0.1.0 " capnweb-client = " 0.1.0 "

Server Example

use capnweb_server :: { Server , ServerConfig , RpcTarget } ; use capnweb_core :: { CapId , RpcError } ; use serde_json :: { json , Value } ; use std :: sync :: Arc ; # [ derive ( Debug ) ] struct Calculator ; impl RpcTarget for Calculator { async fn call ( & self , member : & str , args : Vec < Value > ) -> Result < Value , RpcError > { match member { "add" => { let a = args [ 0 ] . as_f64 ( ) . unwrap ( ) ; let b = args [ 1 ] . as_f64 ( ) . unwrap ( ) ; Ok ( json ! ( a + b ) ) } _ => Err ( RpcError :: not_found ( "method not found" ) ) , } } } # [ tokio :: main ] async fn main ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > { let config = ServerConfig :: default ( ) ; let server = Server :: new ( config ) ; // Register capabilities server . register_capability ( CapId :: new ( 1 ) , Arc :: new ( Calculator ) ) ; // Run server with HTTP batch endpoint server . run ( ) . await ? ; Ok ( ( ) ) }

Client Example

... continue reading