Skip to content

Instantly share code, notes, and snippets.

@Unitech
Created March 24, 2014 10:18
Show Gist options
  • Save Unitech/9737679 to your computer and use it in GitHub Desktop.
Save Unitech/9737679 to your computer and use it in GitHub Desktop.
// partie express
var articles = [];
var id = 0;
app.post('/article/new', function(req, res) {
var article = req.body;
article.id = id;
id++;
articles.push(article);
res.send({ success : true });
});
app.get('/article/:id', function(req, res) {
var id = req.param('id');
articles.forEach(function(article) {
if (article.id == id) {
return res.send(article);
})
});
});
// Front Angularjs
MyCtrl.controller('$http', function($http) {
// recupere un article
$scope.getArticle = function(id) {
$http.get('/article/' + id).success(function(data) {
console.log(data);
})
}
// creer un article
$scope.createArticle = function(monarticle) {
$http.post('/article/new', monarticle).success(function(article) {
console.log(article)
})
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment