Skip to content

A fast RPC protocol that uses WebSockets and MessagePack.

License

Notifications You must be signed in to change notification settings

JoshuaWise/blue-rpc-protocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blue-rpc-protocol

BlueRPC is a fast RPC protocol that uses WebSockets and MessagePack. It solves real-world problems and is very easy to use.

In BlueRPC, streams are first-class data types. You can send streams just like any other value, and BlueRPC automatically handles things like cancellation and backpressure.

Since streams are just regular values, you can easily mix them with structured data, unlike HTTP (where you'd need to use headers or "multipart/form-data" for structured data) or gRPC (where there's no way to directly represent a byte stream) or JSON-RPC (which doesn't support streaming at all).

Here are its features:

  • Byte streams, good for efficiently sending/receiving large payloads such as files.
  • Object streams, good for representing pub-sub subscriptions or observables.
  • Universal web-compatibility, because of WebSockets.
  • Low bandwidth, because of WebSockets, MessagePack, and automatic compression.
  • Simple RPC-style interface.
  • Built-in support for cancelling RPC calls and streams.
  • "Notifications", inspired by JSON-RPC, allow you to push lightweight events to the server.
  • Encodes strings, binary (Buffer or Uint8Array), objects, arrays, floats, integers (BigInt), booleans, null, Error, and streams (stream.Readable or ReadableStream).

BlueRPC can be implemented in any general-purpose programming language. This repository contains a specification and a reference implementation for JavaScript (compatible with Node.js and browsers).

Installation

npm install blue-rpc-protocol

Requires Node.js v16.x.x or later, or any modern browser.

Usage

Server example

const http = require('http');
const BlueRPC = require('blue-rpc-protocol');

const methods = {
    echo: (param) => {
        return param;
    }
};

await BlueRPC.listen({
    methods,
    server: http.createServer(),
    logger: console.log
});

Client example

const BlueRPC = require('blue-rpc-protocol');

const client = BlueRPC.createClient('ws://localhost');

const result = await client.invoke('echo', 'foo');
console.log('result:', result); // => "result: foo"

Documentation

License

MIT

About

A fast RPC protocol that uses WebSockets and MessagePack.

Resources

License

Stars

Watchers

Forks