halacious
Version:
A better HAL processor for Hapi
85 lines (76 loc) • 1.91 kB
JavaScript
'use strict';
var hapi = require('hapi');
var halacious = require('../');
var server = new hapi.Server();
server.connection({ port: 8080 });
server.register(require('vision'), function (err) {
if (err) return console.log(err);
});
server.register({ register: halacious, options: { absolute: true }}, function(err){
if (err) return console.log(err);
var ns = server.plugins.halacious.namespaces.add({ name: 'mycompany', description: 'My Companys namespace', prefix: 'mco'});
ns.rel({ name: 'users', description: 'a collection of users' });
ns.rel({ name: 'user', description: 'a single user' });
ns.rel({ name: 'widgets', description: 'a collection of widgets' });
ns.rel({ name: 'widget', description: 'a single widget' });
});
server.route({
method: 'get',
path: '/users',
config: {
handler: function (req, reply) {
reply({});
},
plugins: {
hal: {
api: 'mco:users'
}
}
}
});
server.route({
method: 'get',
path: '/users/{userId}',
config: {
handler: function (req, reply) {
reply({});
},
plugins: {
hal: {
api: 'mco:user'
}
}
}
});
server.route({
method: 'get',
path: '/widgets',
config: {
handler: function (req, reply) {
reply({});
},
plugins: {
hal: {
api: 'mco:widgets'
}
}
}
});
server.route({
method: 'get',
path: '/widgets/{widgetId}',
config: {
handler: function (req, reply) {
reply({});
},
plugins: {
hal: {
api: 'mco:widget'
}
}
}
});
server.start(function(err){
if (err) return console.log(err);
console.log('Server started at %s', server.info.uri);
});