Minimal NodeJS RPC, Web API
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Minimal Node JS RPC, post to Express-type server.


var express = require('express');
var app = express();

api = {
  servertime: function(){
    return Date();
  echo: function(p){
    return {echo: p};
  something: function(p, req, res){
    // I can access req and res
  someasync: function(p, req, res){
    // I need to be asynchronous
    fs.readFile('some.txt', function(e, r){

require('remote-ex')(api, app);

app.get('/', function(r, s, n){
  s.render('index.html', {});


// rex.js is generated by the server
<script src="rex.js"></script>

// call server functions
   rex.echo({a: 1, b: 2});

Rex lets you call server functions from the browser. It has minimal footprint and works with Express, or other web servers that implement Express functions like .get(), .post(), and req.params.


$ curl --data "" servername/rex/servertime
$ curl --data "q=1" servername/rex/echo
  => {echo: {"q":"1"}}

or /api if you prefer..

$ curl --data "" servername/api/servertime
$ curl --data "q=1" servername/api/echo
  => {echo: {"q":"1"}}

###Handle files

api = {
  myfunc: function(p, r, s){

$ curl -F fn=@file.txt localhost/rex/file

###Authentication Rex is authentication and authorization agnostic, so you're free to select from your options. Then you can authorize in your functions, for instance if the client is providing a cookie token.

api = {
    myfunc: function(p, r, s){
       console.log(r.cookies); // requires cookie handler in Express
       if(r.cookies && r.cookies.token === 'a valid token'){
          return 'yr logged in';
       } else {
          return 'not authorized';

###Why? Page sizes, frameworks have gone nuts in size and browser load. Rex is simple to use. Rex uses only XMLHttp and POST, for maximum browser coverage, and may be especially useful for mobile devices or limited resource environments. There are no server-side requirements except for the web server.