Parameters can be specified in path
property of route configuration
'use strict';
const Hapi = require('hapi');
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
// Add a route path with url param
server.route({
method: 'GET',
path:'/hello/{name}',
handler: function (request, reply) {
// Passed parameter is accessible via "request.params"
return reply(`Hello ${request.params.name}`);
}
});
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});