Skip to content

Repository files navigation

🦍 api-ape

npm versionGitHub issuesZero DependenciesDependabotCSRF protectedBundle SizeJSS Encodinglicense

api-ape logo

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.


Install

npm install api-ape

Requirements: Node.js 14+ (for server), modern browsers (for client)


Quick Start

Server (ape)

const{ createServer }=require('http')const{ ape }=require('api-ape')constserver=createServer()ape(server,{where: 'api'})// Load controllers from ./api folderserver.listen(3000)

Vite Plugin

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.

Controllers

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}}

Client (api)

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

Key Concepts


Examples

cd example/ExpressJs && npm install && npm start

Documentation

DocsDescription
Server READMEAPI reference, lifecycle hooks, auto-routing, file transfers, 🌲 Forest
Client READMEClient usage, connection states, file transfers, security
Auth READMEOPAQUE authentication, tiered access, authorization
Adapters READMEDatabase adapters for Forest

Contributing

  1. Fork the repository
  2. Create a branch: git checkout -b feature/your-feature
  3. Make changes and add tests
  4. Run tests: npm test
  5. Push and open a PR

Tests

npm test# Run tests
npm run test:watch # Watch mode
npm run test:cover # Coverage

License

MITBrian Shannon

Made with 🦍 by the api-ape community

About

RPE: Remote procedure events

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages