Servify
Microservices the simplest way conceivable.
Usage
Create a microservice:
const servify = require("servify");
let count = 0;
servify.api(3000, {
square: (x) => x * x,
concat: (a, b) => a.concat(b),
count: () => count++
}).then(() => console.log("servified port 3000"))
Call a microservice from code:
const servify = require("servify");
const api = servify.at("http://localhost:3000");
api.square(2)
.then(x => console.log(x));
api.concat([1,2], [3,4])
.then(arr => console.log(arr));
api.count()
.then(i => console.log(i));
Call a microservice from the browser / request:
Just access the url followed by a function call:
http:
http:
http:
Support
This requires ES6 Proxy support, so you need node.js 6 and up. Proxies cannot be polyfilled in earlier versions.
Why
When all you want is to create a microservice, Express.js becomes annoyingly verbose. You have to worry about things like serializing/deserializing JSON, chosing how to format query/param inputs, picking a XHR lib on the client and so on. Servify is a ridiculously thin (50 LOC) lib that just standardizes that boring stuff. To create a microservice, all you need is an object of functions specifying your API. To interact with a service, all you need is its URL. You can then call its functions exactly like you would call a normal lib (except it returns a Promise, obviously).