ctx-core rpc


2403.1.02 years ago3 years agoMinified + gzip package size for @ctx-core/rpc in KB



This package is dormant & stripped of functionality, due to ctx-core moving away from Agent objects & using Store instead.

A Remote Procedure Call (rpc) mechanism.

rpc provides an api which exposes functions as a service, while wrapping operations to run auth & whitelist public data.

Since rpc maps to functions, rpc can be a technique of modularizing & composing server code.

Why not just use REST?

In this rpc architecture, REST is used to access call__rpc via POST /rpc in ctx-core/rpc/koa.

rpc is a more primitive network protocol, allowing functions to be directly called.

These same functions may also be wrapped in a RESTful resource.

This of this as composable controller functions or a layer under koa http handlers.

Multiple rpc calls may be invoked & run in parallel or in sequence using a simple functional interface.

Representing a RESTful api as rpc (RESTful prototypes & Refactoring)

With a naming convention, you can depict a RESTful request using a simple function.

get__quovo__account__portfolios simulates GET https://api.quovo.com/v2/accounts/:account_id/portfolios on the server.

Refactoring these methods provides a lightweight way to discover the appropriate RESTful endpoints.


A rpc is run on the server using run__rpc in ctx-core/rpc/lib.

RESTful (koa) request handlers can run__rpc to reuse code & get the benefits of rpc services.


Client Request

A rpc is called on the client via a HTTP POST /rpc accepting json:

    "rpc": ["rpc1", "rpc2", "rpc3"],
    "authentication": "{string|Object}",
    "sample_key_1": "sample_value_1",
    "sample_key_2": "sample_value_2",
    "sample_key_3": "sample_value_3"

The rpc array calls are run in parallel on the first dimension of the array.

The data in the json may set the rpc ctx after being filtered through the run__rpc whitelist in ctx-core/rpc/lib.

In the future, a second dimension may be added to run those rpc calls in sequence.

Client Response

A successful response will by the ctx to be handled by the client.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.