var express = require('express'); var app = express(); app.use(express.bodyParser()); var listes = [ "pain", "sucre" ]; remove_item = function(arr,value){ for(b in arr ){ if(arr[b] == value){ arr.splice(b,1); break; } } return arr; } app.get('/liste', function(req, res) { res.json(listes); // send json response }); app.post('/liste', function(req, res) { if(!req.param('item')) { res.statusCode = 400; return res.send('Error 400: Post syntax incorrect.'); } listes.push(req.param('item')); res.json(true); }); app.delete('/liste', function(req, res) { if(!req.param('item')) { res.statusCode = 400; return res.send('Error 400: Post syntax incorrect.'); } remove_item(listes, req.param('item')); res.json(true); }); app.listen(8080);
{ "name": "serveurrest", "description": "Mon Serveur REST", "version": "0.0.1", "dependencies": { "express": "3.x" } }