Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2013 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4448997 to your computer and use it in GitHub Desktop.
Save anonymous/4448997 to your computer and use it in GitHub Desktop.
test UUU
var express = require('express');
var app = express();
app.use(express.bodyParser());
app.get('/:model', function (req, res) {
res.json(data[req.params.model]);
});
app.get('/:model/:id', function (req, res){
var record = data[req.params.model].filter(function (entry) {
return entry.id == req.params.id;
});
res.json(record[0]);
});
app.post('/:model', function (req, res){
var record = JSON.parse(req.param('entries'));
record.id = '123456';
data[req.params.model].push(record);
res.json(record);
});
app.put('/:model/:id', function (req, res){
var record = data[req.params.model].filter(function (entry) {
return entry.id == req.params.id;
});
var position = data[req.params.model].indexOf(record);
data[req.params.model].splice(position, 1, JSON.parse(req.param[req.param.model]));
res.json(data[req.params.model][position]);
});
app.delete('/:model/:id', function (req, res){
var record = data[req.params.model].filter(function (entry) {
return entry.id == req.params.id;
});
data[req.params.model].splice(data[req.params.model].indexOf(record), 1);
res.json({});
});
app.listen(3000);
console.log('listening');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment