Created
October 15, 2015 22:25
-
-
Save yamikuronue/622a92da64dba105d911 to your computer and use it in GitHub Desktop.
This file contains 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
//Controller module | |
var express = require('express'); | |
var router = express.Router(); | |
app.route('/book') | |
.get(function(req, res) { | |
res.send('Get a random book'); | |
}) | |
.post(function(req, res) { | |
res.send('Add a book'); | |
}) | |
.put(function(req, res) { | |
res.send('Update the book'); | |
}); | |
module.exports = router; | |
//routs.js...? |
This file contains 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
const controller = { | |
getBooks: function(req, res) { | |
res.send('get a random book'); | |
}, | |
addBook: function(req, res) { | |
res.send('add a book') | |
}, | |
updateBook: function(req, res) { | |
res.send('update book') | |
} | |
}; | |
module.export = controller; | |
//route.js | |
const controller = require('./controller.js'); | |
app.route('/book') | |
.get(function(req, res) { | |
controller.getBooks(req,res); | |
}) | |
.post(function(req, res) { | |
controller.addBook(req,res); | |
}) | |
.put(function(req, res) { | |
controller.updateBook(req,res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment