Skip to content

Instantly share code, notes, and snippets.

@kevboutin
Created February 26, 2016 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevboutin/c9fec3c0b1ffab07bc44 to your computer and use it in GitHub Desktop.
Save kevboutin/c9fec3c0b1ffab07bc44 to your computer and use it in GitHub Desktop.
Shows POST and PUT examples in hapi within Node.
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 8000 });
// test by using this on command line:
// http -v --form POST localhost:8000 fname=Kevin lname=Boutin
server.route({
method: ['POST', 'PUT'],
path: '/',
config: {
payload: {
output: 'data',
parse: false,
allow: 'application/json' // comment this line to prevent sending an error back on example
}
},
handler: function(request, response) {
response(request.payload);
}
});
server.start(() => console.log(`Started at ${server.info.uri}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment