Created
September 30, 2017 04:09
-
-
Save idcmardelplata/6553635b3ea9f33dca46f2a190350031 to your computer and use it in GitHub Desktop.
Un ejemplo de algunas rutas en hapi.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.route({ | |
method: 'GET', | |
path: '/mi_path', | |
handler: function(request, reply) { | |
return reply("Hello World"); | |
} | |
}) | |
server.route({ | |
method: 'POST', | |
path: '/upload', | |
handler: function(request, reply) { | |
//los datos que fueron enviados via post | |
//los podes obtener con: | |
var data = request.payload.midato; | |
//ejemplo hiper básico de como retornar codigo html. | |
return reply(`<h1>Has enviado ${data}</h1>`); | |
} | |
}) | |
//tambien podes combinar las rutas de este modo. | |
server.route({ | |
method: ['POST', 'PUT', 'PATH'], | |
path: '/subir', | |
handle: function( request, reply ) { | |
//ejemplo de como retornar un json. | |
return reply({data: request.payload}) | |
} | |
}) | |
//tambien podes unir todas las rutas pasando un array | |
server.route([ | |
{ | |
method: 'GET', | |
path: '/code/{codeId}', | |
handler: function(request, reply) { | |
return reply(`Retorna el codigo con el id ${request.params.codeId}`) | |
} | |
}, | |
{ | |
method: 'POST', | |
path: '/code', | |
handler: function(request, reply) { | |
return reply({data_reciv: request.payload.my_data}) | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment