A node.js module that turns other modules (or other JS libraries) into RESTful web services
MIT License
Service-O-Matic is a module for turning other modules into services.
Email: Iain Collins [email protected] Twitter: @iaincollins
Using Service-O-Matic is very straightforward. Let's take a simple example service like the Random Password Generator.
It's normally invoked like this:
var passwordGenerator = require('random-password-generator');
var newPassword = passwordGenerator.generate();
To expose it as a webservice with Service-O-Matic, all you need to do is:
var service = require('service-o-matic');
service.addService('Password Generator', require('random-password-generator'));
service.startServices();
The following example shows how to turn modules which provide a Dictionary lookup and a Thesaurus checker into services.
The homepage of the server ("/") will list all the services currently being exposed - you can then click through to see their methods and the arguments each method takes and test them out.
In this example the third argument is passed - an array of methods to expose (which overrides the default behaviour, which is to expose all methods).
var service = require('service-o-matic');
service.addService('Dictionary', require('wordnet'), ['lookup']);
service.addService('Thesaurus', require('thesaurus'), ['find']);
service.startServices();
Some modules provide a range of features and you might need to expose elements of them as seperate services. The below example shows how to expose 3 different services from the countryData module:
var service = require('service-o-matic');
var countryData = require('country-data');
service.addService('Countries', countryData.countries,);
service.addService('Regions', countryData.regions);
service.addService('Currencies', countryData.currencies);
service.startServices(8080);
In the example above a port number has also been passed to startService().
You can also specify the port via the PORT shell variable.