Remote Procedure Events (RPE) — A lightweight WebSocket framework for building real-time APIs. Call server functions from the browser like local methods. Get real-time broadcasts with zero setup.
npm install api-apeRequirements: Node.js 14+ (for server), modern browsers (for client)
const{ createServer }=require('http')const{ ape }=require('api-ape')constserver=createServer()ape(server,{where: 'api'})// Load controllers from ./api folderserver.listen(3000)For Vite projects, use the built-in plugin for plug-and-play integration:
// vite.config.jsimport{defineConfig}from'vite'importapiApefrom'api-ape/vite'exportdefaultdefineConfig({plugins: [apiApe({where: 'api',onConnect: './ape/onConnect',// Optional: path to connection handlerlogging: false,// Optional: silence api-ape dev-server framework logs})]})Run npm run dev — api-ape runs directly on Vite's dev server. No proxy needed.
Drop a file in your api/ folder — it automatically becomes an endpoint:
// api/hello.jsmodule.exports=function(name){return`Hello, ${name}!`}// api/message.js module.exports=function(text){this.broadcastOthers('message',{ text,from: this.clientId})return{sent: true}}Browser:
<scriptsrc="/api/ape.js"></script><script>constresult=awaitapi.hello('World')// "Hello, World!"// Subscribe to messages (pass a callback)constunsub=api.message(data=>console.log(data))</script>Bundlers (React, Vue, etc.):
importapifrom'api-ape'constresult=awaitapi.hello('World')// Subscribe (pass callback) vs RPC call (pass data)constunsub=api.message(data=>console.log(data))// Subscribeawaitapi.message({text: 'Hello'})// RPC call- Auto-wiring — Drop JS files in a folder, they become API endpoints
- Real-time broadcasts — Built-in
broadcast()andbroadcastOthers()methods - Pub/Sub channels — Clients subscribe to channels, server publishes updates
- Promise-based calls —
api.users.list()maps toapi/users/list.js - Automatic reconnection — Client reconnects with exponential backoff
- HTTP fallback — Falls back to long polling when WebSockets are blocked
- JSS Encoding — Supports Date, RegExp, Error, Set, Map over the wire
- 🌲 Forest — Distributed mesh for horizontal scaling
- 🔐 Authentication — OPAQUE/PAKE auth with tiered access control
- Framework logging — Silence or redirect internal api-ape diagnostics (
logging/configureApeLogging)
example/ExpressJs/— Simple real-time chatexample/NextJs/— Production chat with React & Dockerexample/Vite/— Vite + Vueexample/Bun/— Bun runtime
cd example/ExpressJs && npm install && npm start| Docs | Description |
|---|---|
| Server README | API reference, lifecycle hooks, auto-routing, file transfers, 🌲 Forest |
| Client README | Client usage, connection states, file transfers, security |
| Auth README | OPAQUE authentication, tiered access, authorization |
| Adapters README | Database adapters for Forest |
- Fork the repository
- Create a branch:
git checkout -b feature/your-feature - Make changes and add tests
- Run tests:
npm test - Push and open a PR
npm test# Run tests
npm run test:watch # Watch mode
npm run test:cover # CoverageMIT — Brian Shannon
Made with 🦍 by the api-ape community
