Playing with REST using hepi Expoloring hepi REST by making simple project
- Creating server
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 8080 });
server.start(function () {
console.log('Server running at:', server.info.uri);
});
- Ading route
//GET /
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Hello, world!');
}
});
// GET /{name}
server.route({
method: 'GET',
path: '/{name}',
handler: function (request, reply) {
reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
}
});