2 * Using Rails-like standard naming convention for endpoints.
4 * POST /things -> create
5 * GET /things/:id -> show
6 * PUT /things/:id -> update
7 * DELETE /things/:id -> destroy
12 var _ = require('lodash');
13 var Thing = require('../../models').Thing;
16 exports.index = function(req, res, next) {
19 .then(function(things) {
20 return res.status(200).send(things);
22 .catch(function(err) {
28 exports.show = function(req, res, next) {
30 .findById(req.params.id)
31 .then(function(thing) {
33 return res.sendStatus(404);
35 return res.send(thing);
37 .catch(function(err) {
42 // Creates a new thing in the DB.
43 exports.create = function(req, res, next) {
46 .then(function(thing) {
47 return res.status(201).send(thing);
49 .catch(function(err) {
54 // Updates an existing thing in the DB.
55 exports.update = function(req, res, next) {
60 .findById(req.params.id)
61 .then(function(thing) {
63 return res.sendStatus(404);
65 var updated = _.merge(thing, req.body);
68 return res.status(200).send(thing);
70 .catch(function(err) {
74 .catch(function(err) {
79 // Deletes a thing from the DB.
80 exports.destroy = function(req, res, next) {
82 .findById(req.params.id)
83 .then(function(thing) {
85 return res.sendStatus(404);
89 return res.sendStatus(204);
91 .catch(function(err) {
95 .catch(function(err) {