node package manager

hook.io-restful

RESTful interface for hook's, provides a RESTful web server for surfaced hooks

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.

installation

installing npm (node package manager)

  curl http://npmjs.org/install.sh | sh

installing hook.io

  npm install hook.io

installing hook.io-RESTful

  npm install hook.io-restful

Hook.io-restful config.json settings

{
  port: 8080, // port to use for HTTP communications 
  debug: true
}

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.exports._hello = self.hello;
  self.exports._hello.description = 'Returns Hello World! if no name is specified or Hello <Name>! if name is specified.';
  self.exports._hello.schema = {
    name: {
      required: false,
      validation: 'string',
      description: 'The name to return in place of World.',
    }
  };
  self.exports._hello.route = 'hello';
 
  self.exports.sayHello = self.sayHello;
  self.exports.sayHello.description = 'Returns Hello World! if no name is specified or Hello <Name>! if name is specified.';
  self.exports.sayHello.schema = {
    name: {
      required: false,
      validation: 'string',
      description: 'The name to return in place of World.',
    }
  };
  
  self.exports.sayHelloTo = self.sayHelloTo;
  self.exports.sayHelloTo.description = 'Returns Hello World! if no name is specified or Hello <Name>! if name is specified.';
  self.exports.sayHelloTo.schema = {
    name: {
      required: true,
      validation: /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/gi,
      description: 'The name to return in place of World.',
    }
  };
};
 
util.inherits(helloWorldHook, RESTfulHook);
 
helloWorldHook.prototype.hello = function(data, callback){
  if(!(data&&data.name)) callback(null, 'Hello world!');
  else callback(null, 'Hello '+data.name);
};
 
helloWorldHook.prototype.sayHello = function(data, callback){
  if(!(data&&data.name)) callback(null, 'Hello world!');
  else callback(null, 'Hello '+data.name);
};
 
helloWorldHook.prototype.sayHelloTo = function(data, callback){
  if(!(data&&data.name)) callback({error: 'No name specified'});
  else callback(null, 'Hello '+data.name);
};
 
 
/* 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();