Created
September 4, 2013 23:10
-
-
Save particlebanana/6444048 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic Sails Router Example | |
// config/routes.js | |
module.exports.routes = { | |
'get /users': { | |
controller: 'user', | |
action: 'index' | |
}, | |
'get /users/:id': { | |
controller: 'user', | |
action: 'show' | |
}, | |
'post /users': { | |
controller: 'user', | |
action: 'create' | |
}, | |
// You could also use the following syntax | |
'put /users/:id': 'UserController.update' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple User model | |
// /api/models/User.js | |
module.exports = { | |
attributes: { | |
name: 'string' | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple JSON controller method without error handling | |
// /api/controllers/UserController.js | |
module.exports = { | |
index: function(req, res) { | |
User.find().exec(function(err, users) { | |
res.json(users); | |
}); | |
}, | |
show: function(req, res) { | |
var id = req.param('id'); | |
User.findOne(id).exec(function(err, user) { | |
res.json(user); | |
}); | |
}, | |
create: function(req, res) { | |
User.create(req.params.all()).exec(function(err, user) { | |
res.json(user); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment