0.0.4 • Published 12 years ago
hook.io-restful v0.0.4
hook.io-restful
A hook to surface chosen hooks to the rest of the world via a RESTful interface. Hooks choose to register and provide documentation details.
Hook.io config.json settings
{
port: 8080
}
UNDER CONSTRUCTION
This hook is very much under construction with many things changing, but wanted to get it up for feedback.
Hook.io Events Names
RESTfulReady Notify's RESTfulHook's that a RESTfulServer is available to serve requests.
/* helloWorldHook.js */
var RESTfulHook = require('../../lib/restful').RESTfulHook,
util = require('util');
var helloWorldHook = exports.helloWorldHook = function(options){
var self = this;
RESTfulHook.call(self, options);
self.exports(self._hello);
self.exports(self.sayHello);
};
util.inherits(helloWorldHook, RESTfulHook);
helloWorldHook.prototype._hello = function(ssid, details){
if(details.query&&details.query.name) myHook.sendResponse(ssid, 'Hello '+details.query.name+'!');
else myHook.sendResponse(ssid, 'Hello World!');
};
helloWorldHook.prototype._hello.description = 'Returns Hello World! if no name is specified or Hello <Name>! if name is specified.';
helloWorldHook.prototype._hello.schema = {
name: {
required: false,
validation: 'string',
description: 'The name to return in place of World.',
}
};
helloWorldHook.prototype._hello.route = 'hello';
helloWorldHook.prototype.sayHello = function(ssid, details){
if(details.query&&details.query.name) myHook.sendResponse(ssid, 'Hello '+details.query.name+' 2!');
else myHook.sendResponse(ssid, 'Hello World 2!');
};
helloWorldHook.prototype.sayHello.description = 'Returns Hello World! if no name is specified or Hello <Name>! if name is specified.';
helloWorldHook.prototype.sayHello.schema = {
name: {
required: false,
validation: 'string',
description: 'The name to return in place of World.',
}
};
/* helloWorld.js */
/* This is basically a way to instanciate the helloWorldHook without using .spawn */
#!/usr/bin/env node
var Helloworld = require('./helloWorldHook').helloWorldHook;
var myHook = new Helloworld();
myHook.start();