'use strict'; /* npm install hapi@8.x.x node thisfile.js curl -XPOST http://localhost:4000/v1/lead/property */ var Hapi = require('hapi'); var server = new Hapi.Server(); var count = 0; server.connection({ port: 4000 }); server.route([ { method: 'POST', path: '/v1/lead/property', handler: function (request, reply) { count++; if (count % 2 === 0) { return reply({success: true}); } reply(new Error('Invalid count')); } } ]); server.start();