No REST for Cap'n Web

This ad is not shown to multipass and full ticket holders
React Summit
React Summit 2026
June 11 - 15, 2026
Amsterdam & Online
The biggest React conference worldwide
Upcoming event
React Summit 2026
React Summit 2026
June 11 - 15, 2026. Amsterdam & Online
Learn more
Bookmark
Rate this content
Sentry
Promoted
Code breaks, fix it faster

Crashes, slowdowns, regressions in prod. Seer by Sentry unifies traces, replays, errors, profiles to find root causes fast.

Cap'n Web is a new open source library that lets you expose JavaScript and TypeScript APIs across the Web, including over HTTP or WebSocket. Unlike almost all other RPC systems before it, Cap'n Web supports passing functions and objects over RPC "by reference". This simple-sounding feature has deep implications that completely change how APIs are designed. In this talk I will present a series of examples showing how to use Cap'n Web's first-class functions and objects to implement a variety of common API design patterns, such as authorization, pub-sub, and streaming. I will show how Cap'n Web can integrate nicely with reactive UI frameworks, and even touch briefly on how it can be a powerful tool for sandboxing AI agents.

This talk has been presented at Node Congress 2026, check out the latest edition of this JavaScript Conference.

FAQ

CapnWeb is an RPC (remote procedure call) protocol that allows communication between a client and server through function calls rather than requests and responses.

CapnWeb uses RPC function calls instead of REST's requests and responses, making it more intuitive and efficient, as it resembles calling a library rather than a network service.

CapnWeb supports JavaScript runtimes, works best over WebSocket, uses JavaScript proxy objects for stubs, supports capability-based security, and offers promise pipelining for efficient communication.

Promise pipelining in CapnWeb allows a client to queue up a series of method calls and send them in one round trip to the server, improving performance and reducing latency.

Capability-based security in CapnWeb restricts what an AI agent can do by giving it only the necessary stubs for certain actions, simplifying security management.

Yes, CapnWeb is not exclusive to Cloudflare Workers and supports all JavaScript runtimes.

CapnWeb simplifies security for AI agents through capability-based security, reducing the risk of token leaks and unauthorized actions, and provides a simpler interface for AI understanding.

CapnWeb works best over WebSocket because it allows for efficient, real-time communication and supports advanced features like promise pipelining.

Kenton Varda is the lead developer of the Cloudflare Workers Developer Platform, creator of CapnProto, and the developer behind CapnWeb.

CapnWeb allows authorization to be factored out by using an 'authorize' method that returns a new object with authorized access, eliminating the need to pass tokens with each request.

Kenton Varda
Kenton Varda
23 min
26 Mar, 2026

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Kenton Varda advocates for using CapnWeb, an RPC protocol, over REST for web APIs, emphasizing benefits for humans and AI agents. CapnWeb simplifies client-server communications by treating them as function calls. TypeScript type checking ensures method accuracy in CapnWeb across JavaScript runtimes. Stubs in CapnWeb allow method calls to execute on remote objects and simulate all possible method names for remote calls. Converting REST APIs to CapnWeb streamlines code and improves API calls. CapnWeb enhances API functionality with object-specific RPC sessions and promises pipelining for multilevel API optimization. AI agent security challenges are addressed with sandboxing and token protection in CapnWeb. CapnWeb capabilities for AI agents include passing restricted CapnWeb stubs and exploring capability-based security with CapnProto.
Available in Español: No REST para Cap'n Web

1. Introduction to CapnWeb

Short description:

Kenton Varda, lead developer of Cloudflare Workers Developer Platform and creator of CapnWeb, advocates for using CapnWeb over REST for web APIs, emphasizing its benefits for humans and AI agents. CapnWeb is an RPC protocol that simplifies client-server communications by treating them as function calls, resembling invoking a library. Implementing CapnWeb involves defining an RPC interface on the server side and setting up client-server communication through methods like greet.

Hello. Thanks for coming. My name is Kenton Varda. I'm the lead developer of the Cloudflare Workers Developer Platform, a project I started about nine years ago. I'm also the creator of CapnProto and now CapnWeb. Today, I would like to convince you that if everyone used CapnWeb instead of REST for web APIs, the world would be a better place, both for humans and for AI agents.

So what is CapnWeb? CapnWeb is an RPC protocol. RPC stands for remote procedure call. And the idea is that you are expressing your communications between a client and a server as function calls rather than as requests and responses. And so it feels like the communications, it's like calling a library instead of calling a network service.

So what does that look like with CapnWeb? This is a very basic hello world, CapnWeb client and server. So on the server side, we declare this class, which defines our RPC interface. So all the methods of this class are going to be exposed to the client. So we have a greet method here. It returns hello name. And then down here is basically the boilerplate to set up to accept these RPC requests in CloudFlare Workers.

2. Using CapnWeb Across JavaScript Runtimes

Short description:

CapnWeb, compatible with various JavaScript runtimes, utilizes WebSocket for efficient client-server communication. TypeScript type checking ensures method accuracy, avoiding runtime errors. Importing server types into CapnWeb enables correct method structures without interdependencies, promoting seamless client-server interaction.

So CapnWeb is not exclusive to CloudFlare Workers. It supports all JavaScript runtimes. However, the code varies slightly for each runtime. In this case, CloudFlare Workers are used, employing a standard HTTP handler that utilizes the CapnWeb library to handle requests and expose server instances to clients.

On the client side, the process is straightforward. The client initiates a new RPC session via WebSocket to a specified URL using CapnWeb. Although CapnWeb does support plain HTTP transport and other options, WebSocket is preferred for its efficiency. The client receives an RPC stub, which serves as a reference to a remote object, allowing method calls that trigger corresponding actions on the server.

Despite the stub's lack of knowledge about server methods, TypeScript type checking ensures method validity at coding time. By importing server types into CapnWeb, the client gains access to the correct method structures without creating interdependencies between client and server code. Alternatively, clients can use a separate TypeScript interface file for method definition, enabling seamless communication between client and server components.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
Rome, a Modern Toolchain!
JSNation 2023JSNation 2023
31 min
Rome, a Modern Toolchain!
Top Content
Rome is a toolchain built in Rust that aims to replace multiple tools and provide high-quality diagnostics for code maintenance. It simplifies tool interactions by performing all operations once, generating a shared structure for all tools. Rome offers a customizable format experience with a stable formatter and a linter with over 150 rules. It integrates with VCS and VLSP, supports error-resilient parsing, and has exciting plans for the future, including the ability to create JavaScript plugins. Rome aims to be a top-notch toolchain and welcomes community input to improve its work.
Conquering Complexity: Refactoring JavaScript Projects
JSNation 2024JSNation 2024
21 min
Conquering Complexity: Refactoring JavaScript Projects
Top Content
Today's Talk explores the complexity in code and its impact. It discusses different methods of measuring complexity, such as cyclomatic complexity and cognitive complexity. The importance of understanding and conquering complexity is emphasized, with a demo showcasing complexity in a codebase. The Talk also delves into the need for change and the role of refactoring in dealing with complexity. Tips and techniques for refactoring are shared, including the use of language features and tools to simplify code. Overall, the Talk provides insights into managing and reducing complexity in software development.
Improving Developer Happiness with AI
React Summit 2023React Summit 2023
29 min
Improving Developer Happiness with AI
Watch video: Improving Developer Happiness with AI
GitHub Copilot is an auto-completion tool that provides suggestions based on context. Research has shown that developers using Copilot feel less frustrated, spend less time searching externally, and experience less mental effort on repetitive tasks. Copilot can generate code for various tasks, including adding modals, testing, and refactoring. It is a useful tool for improving productivity and saving time, especially for junior developers and those working in unfamiliar domains. Security concerns have been addressed with optional data sharing and different versions for individuals and businesses.
Automate the Browser With Workers Browser Rendering API
JSNation 2024JSNation 2024
20 min
Automate the Browser With Workers Browser Rendering API
The Talk discusses browser automation using the Worker's Browser Rendering API, which allows tasks like navigating websites, taking screenshots, and creating PDFs. Cloudflare integrated Puppeteer with their workers to automate browser tasks, and their browser rendering API combines remote browser isolation with Puppeteer. Use cases for the API include taking screenshots, generating PDFs, automating web applications, and gathering performance metrics. The Talk also covers extending sessions and performance metrics using Durable Objects. Thank you for attending!
Static Analysis in JavaScript: What’s Easy and What’s Hard
JSNation 2023JSNation 2023
23 min
Static Analysis in JavaScript: What’s Easy and What’s Hard
Static analysis in JavaScript involves analyzing source code without executing it, producing metrics, problems, or warnings. Data flow analysis aims to determine the values of data in a program. Rule implementation in JavaScript can be straightforward or require extensive consideration of various cases and parameters. JavaScript's dynamic nature and uncertainty make static analysis challenging, but it can greatly improve code quality.

Workshops on related topic

Pragmatic 101 on Custom JS Tooling for Your Project
JSNation US 2025JSNation US 2025
122 min
Pragmatic 101 on Custom JS Tooling for Your Project
Featured Workshop
Will Klein
Will Klein
Let’s demystify the secrets of modern JavaScript tooling. In this workshop, you will learn how linters, compilers, and code transforms work. You will take your first steps building your own developer tools, writing an ESLint rule, a compiler plugin, and a code transformation. Learn these skills to help your team and deepen your understanding of computer languages.Workshop Plan:A preview of how ASTs can be usedA brief walkthrough of how compilers workAn intro to working with an ASTThe secret to making thousands of changes in secondsHow to apply this skill
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
JSNation 2023JSNation 2023
44 min
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
WorkshopFree
Ryan Albrecht
Ryan Albrecht
You know that annoying bug? The one that doesn’t show up locally? And no matter how many times you try to recreate the environment you can’t reproduce it? You’ve gone through the breadcrumbs, read through the stack trace, and are now playing detective to piece together support tickets to make sure it’s real.
Join Sentry developer Ryan Albrecht in this talk to learn how developers can use Session Replay - a tool that provides video-like reproductions of user interactions - to identify, reproduce, and resolve errors and performance issues faster (without rolling your head on your keyboard).