npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fib-rpc

v0.5.3

Published

Remote Procedure Calling for fibjs

Downloads

47

Readme

fib-rpc

NPM version Build Status Build status

Remote Procedure Calling for fibjs

Introduction

fib-rpc is working on dispatching of remote procedure calling, it supports both http request and websocket(recommended).

obviously, it follows JSON-RPC protocol.

Get Started

npm i -S fib-rpc

Usage

you can use it with http.Request

var js_remote = rpc.handler({
    foo: function (p1, p2) {
        return p1 + ',' + p2;
    }
});

function js_call(r) {
    var m = new http.Request();

    m.value = 'test/tttt/tttt/';
    m.json(r);

    js_remote(m);

    m.response.body.rewind();
    return m.response.readAll().toString();
}

var result = js_call({
    // method is required
    method: 'foo',
    // params is required and must be array
    params: [100, 200],
    // id is required
    id: 1234
})

assert.equal(result, '{"id":1234,"result":"100,200"}');

but in most cases, you may prefer using it based on Websocket, which finshied by rpc.connect

const ws = require('ws')
const http = require('http')

const rpc = require('fib-rpc')

const svr = new http.Server(8811, ws.upgrade(
    rpc.handler(
        {
            test: function (v1, v2) {
                return v1 + v2;
            }
        }
    ))
);
svr.asyncRun();

const remoting = rpc.connect("ws://127.0.0.1:8811");

remoting.test(1, 2) // 3

Learn connect from test case 'websocket rpc' in exmaple.

Custom Errors

use RpcError as typed Error thrown if required:

const rpc = require('fib-rpc')

const js_remote = rpc.handler(
    {
        integerAdd: function (v1, v2) {
            if (!Number.isInteger(v1) || !Number.isInteger(v2))
                throw rpc.rpcError(4010000, 'Addend must be integer')
                
            return v1 + v2;
        }
    }
);

const svr = new http.Server(8811, ws.upgrade(js_remote));

const remoting = rpc.connect("ws://127.0.0.1:8811");

try {
    remoting.integerAdd(1.1, 2)
} catch (err_msg) {
    console.log(err_msg) // 'Addend must be integer'
}

console.log(
    js_call({
        method: 'foo',
        params: [1.1, 2],
        id: 1234
    })
) // code: 4010000, message: 'Addend must be integer'

Samples

View Samples, test them like this:

# build lib first.
npm i && npm run build

# chdir to examples
cd exapmles
npm i

# run example
fibjs ./connect.js
fibjs ./open_handler-js.js