bridle

Javscript black magic RPC over websockets.

Bridle: Black magic Javascript RPC

Installation

npm install --save bridle

Bridle allows exporting functions from a Node.js server and then calling them natively from a client (both Node and browsers are supported).

Remote functions will be ran on the server, with communication occurring using WebSocket transport. Local functions will be ran natively on the client as is.

Note: This project exists because it can, not because it should. The author takes no responsibility for any [mis]use.

Usage

Server:

const Bridle = require('bridle');

new Bridle.Server({
    port: 7777,
    localFunctions: {
        foo: () => {
            console.log('bar');
        }
    },
    remoteFunctions: {
        hello: (name) => 'Hello ' + name
    }
});

Client:

import {Client} from 'bridle';

const rpc = new Client();

rpc.connect('ws://localhost:7777')

    .then(functions => {

        functions.foo();

        functions.hello('world!').then(result => {
            console.log(result);
        }).catch(error => {
            console.log(error);
        });
    });

Output:

$ bar
$ Hello world!

Support

Tested in Node.js v6.10.0, Chrome 63

License

ISC

HomePage

https://github.com/lexe11/bridle

Repository

git+https://github.com/lexe11/bridle.git


相关推荐

暂无相关文章