<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Cap&#x27;n Web: a new RPC system for browsers and web servers with AMAZING features]]></title><description><![CDATA[<p dir="auto">Full Read well worth it: <a href="https://blog.cloudflare.com/capnweb-javascript-rpc-library/" target="_blank" rel="noopener noreferrer nofollow ugc">https://blog.cloudflare.com/capnweb-javascript-rpc-library/</a></p>
<p dir="auto">This would be a huge boost for Cloudron 9.x!</p>
<p dir="auto">12 min read</p>
<p dir="auto"><img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5i59EQLnkQYe3oZrCzCk1y/43c20e671782e6ec9f878f786535bd15/BLOG-2954_1.png" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Allow us to introduce <a href="https://github.com/cloudflare/capnweb" target="_blank" rel="noopener noreferrer nofollow ugc">Cap'n Web</a>, an RPC protocol and implementation in pure TypeScript.</p>
<p dir="auto">Cap'n Web is a spiritual sibling to <a href="https://capnproto.org/" target="_blank" rel="noopener noreferrer nofollow ugc">Cap'n Proto</a>, an RPC protocol I (Kenton) created a decade ago, but designed to play nice in the web stack. That means:</p>
<ul>
<li>
<p dir="auto">Like Cap'n Proto, it is an object-capability protocol. ("Cap'n" is short for "capabilities and".) We'll get into this more below, but it's incredibly powerful.</p>
</li>
<li>
<p dir="auto">Unlike Cap'n Proto, Cap'n Web has <em>no schemas</em>. In fact, it has almost no boilerplate whatsoever. This means it works more like the <a href="https://blog.cloudflare.com/javascript-native-rpc/" target="_blank" rel="noopener noreferrer nofollow ugc">JavaScript-native RPC system in Cloudflare Workers</a>.</p>
</li>
<li>
<p dir="auto">That said, it integrates nicely with TypeScript.</p>
</li>
<li>
<p dir="auto">Also unlike Cap'n Proto, Cap'n Web's underlying serialization is human-readable. In fact, it's just JSON, with a little pre-/post-processing.</p>
</li>
<li>
<p dir="auto">It works over HTTP, WebSocket, and postMessage() out-of-the-box, with the ability to extend it to other transports easily.</p>
</li>
<li>
<p dir="auto">It works in all major browsers, Cloudflare Workers, Node.js, and other modern JavaScript runtimes.</p>
</li>
<li>
<p dir="auto">The whole thing compresses (minify+gzip) to under 10 kB with no dependencies.</p>
</li>
<li>
<p dir="auto"><a href="https://github.com/cloudflare/capnweb" target="_blank" rel="noopener noreferrer nofollow ugc">It's open source</a> under the MIT license.</p>
</li>
</ul>
<p dir="auto">Cap'n Web is more expressive than almost every other RPC system, because it implements an <strong>object-capability RPC model</strong>. That means it:</p>
<ul>
<li>
<p dir="auto">Supports bidirectional calling. The client can call the server, and the server can also call the client.</p>
</li>
<li>
<p dir="auto">Supports passing functions by reference: If you pass a function over RPC, the recipient receives a "stub". When they call the stub, they actually make an RPC back to you, invoking the function where it was created. This is how bidirectional calling happens: the client passes a callback to the server, and then the server can call it later.</p>
</li>
<li>
<p dir="auto">Similarly, supports passing objects by reference: If a class extends the special marker type <code>RpcTarget</code>, then instances of that class are passed by reference, with method calls calling back to the location where the object was created.</p>
</li>
<li>
<p dir="auto">Supports promise pipelining. When you start an RPC, you get back a promise. Instead of awaiting it, you can immediately use the promise in dependent RPCs, thus performing a chain of calls in a single network round trip.</p>
</li>
<li>
<p dir="auto">Supports capability-based security patterns.</p>
</li>
</ul>
<p dir="auto">In short, Cap'n Web lets you design RPC interfaces the way you'd design regular JavaScript APIs – while still acknowledging and compensating for network latency.</p>
<p dir="auto">The best part is, Cap'n Web is absolutely trivial to set up.</p>
<p dir="auto">A client looks like this:</p>
<pre><code>import { newWebSocketRpcSession } from "capnweb";

// One-line setup.
let api = newWebSocketRpcSession("wss://example.com/api");

// Call a method on the server!
let result = await api.hello("World");

console.log(result);
</code></pre>
<p dir="auto">And here's a complete Cloudflare Worker implementing an RPC server:</p>
<pre><code>import { RpcTarget, newWorkersRpcResponse } from "capnweb";

// This is the server implementation.
class MyApiServer extends RpcTarget {
  hello(name) {
    return `Hello, ${name}!`
  }
}

// Standard Workers HTTP handler.
export default {
  fetch(request, env, ctx) {
    // Parse URL for routing.
    let url = new URL(request.url);

    // Serve API at `/api`.
    if (url.pathname === "/api") {
      return newWorkersRpcResponse(request, new MyApiServer());
    }

    // You could serve other endpoints here...
    return new Response("Not found", {status: 404});
  }
}
</code></pre>
<p dir="auto">That's it. That's the app.</p>
<ul>
<li>
<p dir="auto">You can add more methods to <code>MyApiServer</code>, and call them from the client.</p>
</li>
<li>
<p dir="auto">You can have the client pass a callback function to the server, and then the server can just call it.</p>
</li>
<li>
<p dir="auto">You can define a TypeScript interface for your API, and easily apply it to the client and server.</p>
</li>
</ul>
<p dir="auto">It just works.</p>
<p dir="auto">Much more at the <a href="https://blog.cloudflare.com/capnweb-javascript-rpc-library/" target="_blank" rel="noopener noreferrer nofollow ugc">link above</a>.</p>
]]></description><link>https://forum.cloudron.io/topic/14374/cap-n-web-a-new-rpc-system-for-browsers-and-web-servers-with-amazing-features</link><generator>RSS for Node</generator><lastBuildDate>Tue, 16 Jun 2026 15:37:49 GMT</lastBuildDate><atom:link href="https://forum.cloudron.io/topic/14374.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Oct 2025 19:02:17 GMT</pubDate><ttl>60</ttl></channel></rss>