8000 GitHub - gavinhungry/proximal: Minimal JSON RPC over HTTP with Proxy/Promise interface
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gavinhungry/proximal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

proximal

Minimal JSON RPC over HTTP with Proxy/Promise interface.

Installation

$ npm install proximal

Usage

Server

const proximal = require('proximal');

let rpc = new proximal.Server({
  modules: {
    foo: require('foo'),
    bar: require('bar')
  }
});

Middleware

const express = require('express');
let app = express();

app.post('/rpc', rpc.middleware());
app.listen(8888);

Client

let rpc = new proximal.Client({
  url: 'http://example.tld:8888/rpc'
});

let foo = rpc.getModule('foo');

foo.doSomething('arg1', 'arg2').then(result => {
  // your result from remote `foo.doSomething` method here
});

foo.doesNotExist('arg1').then(null, err => {
  // Error: method not found
});

let doesNotExist = rpc.getModule('doesNotExist');
doesNotExist.doSomething().then(null, err => {
  // Error: module not found
});

Node.js

The client object is designed for use in the browser. However, pass an optional XMLHttpRequest constructor to the proximal.Client constructor to use it in a Node.js environment:

let XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;

let rpc = new proximal.Client({
  url: 'http://example.tld:8888/rpc',
  xhr: XMLHttpRequest
});

License

This software is released under the terms of the MIT license. See LICENSE.

About

Minimal JSON RPC over HTTP with Proxy/Promise interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0