Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Last active May 14, 2017 18:51
Show Gist options
  • Save gorkamu/c20b8a948bfb6891c7125f75f83ede8b to your computer and use it in GitHub Desktop.
Save gorkamu/c20b8a948bfb6891c7125f75f83ede8b to your computer and use it in GitHub Desktop.
Ejemplo de método POST en una API REST con Node.js
function saveAlbum(req, res){
var album = new Album();
var params = req.body;
album.title = params.title;
album.band = params.band;
album.genre = params.genre;
album.year = params.year;
album.save(function(err, albumStored){
if(err){
res.status(500).send({message:'Error al guardar el album'});
}else{
res.status(200).send({album: albumStored});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment