var express = require('express');
var router = express.Router();

var TagDB = require('../models/tag');

var data = [
    {
        _id: 0,
        alias: 'Labor'
    },
    {
        _id: 1,
        alias: 'Mensa'
    }
];

/* GET users listing. */
router.get('/', function(req, res, next) {
    res.send(data);
});

router.get('/:id', function(req, res, next){
    var id = req.params.id;
    console.log(id);
    res.send(findById(id));
});

function findById(id){
    for(var i = 0; i < data.length; i++){
        if(data[i]._id == id){
            return data[i];
        }
    }
}

module.exports = router;

@@ -102,346 +102,1209 @@
 );%0A%0A
-var data = %5B%0A    %7B%0A        _id: 0,%0A        alias: 'Labor'%0A    %7D,%0A    %7B%0A        _id: 1,%0A        alias: 'Mensa'%0A    %7D%0A%5D;%0A%0A/* GET users listing. */%0Arouter.get('/', function(req, res, next) %7B%0A    res.send(data);%0A%7D);%0A%0Arouter.get('/:id', function(req, res, next)%7B%0A    var id = req.params.id;%0A    console.log(id);%0A    res.send(findById(id));%0A
+router.get('/', getAllEntries);%0Arouter.get('/:id', getOneEntry);%0Arouter.post('/', createEntry);%0Arouter.put('/:id', updateEntry);%0Arouter.delete('/:id', deleteEntry);%0A%0Afunction getAllEntries(req, res, next)%7B%0A    TagDB.find(function(err, entries)%7B%0A        if(err)%7B%0A            res.send(err);%0A        %7D%0A        res.send(entries);%0A    %7D);%0A%7D%0A%0Afunction getOneEntry(req, res, next)%7B%0A    var id = req.params.id;%0A    TagDB.findById(id, function(err, entry)%7B%0A       if(err)%7B%0A           res.send(err);%0A       %7D%0A       res.send(entry);%0A    %7D);%0A%7D%0A%0Afunction createEntry(req, res, next)%7B%0A    var tag = new TagDB();%0A    tag.id = req.body.id;%0A    tag.alias = req.body.alias;%0A%0A    tag.save(function(err)%7B%0A        if(err)%7B%0A            res.send(err);%0A        %7D%0A        res.send(%7B message: 'tag created'%7D);%0A    %7D);%0A%7D%0A%0Afunction updateEntry(req, res, next)%7B%0A    var id = req.params.id;%0A    TagDB.findById(id, function(err, entry)%7B%0A        if(err)%7B%0A            res.send(err);%0A        %7D%0A        entry.id = req.body.id;%0A        entry.alias = req.body.alias;%0A        entry.save(function(err)%7B%0A            if(err)%7B%0A                res.send(err);%0A            %7D%0A            res.send(%7B message: 'tag updated'%7D);%0A        %7D);%0A    
 %7D);
+%0A%7D
 %0A%0Afu
@@ -1314,138 +1314,235 @@
 ion 
-findById(id
+deleteEntry(req, res, next
 )%7B%0A    
-for(
 var i
+d
  = 
-0; i %3C data.length; i++)%7B%0A        if(data%5Bi%5D._id == id)%7B%0A            return data%5Bi%5D;%0A        %7D%0A    %7D
+req.params.id;%0A    TagDB.remove(%7B%0A        _id: id%0A    %7D, function(err, entry)%7B%0A        if(err)%7B%0A            res.send(err);%0A        %7D%0A        res.send(%7B message: 'tag deleted'%7D);%0A    %7D);
 %0A%7D%0A%0A

complete tag REST implementation