forked from scotch-io/node-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Sevilleja
committed
Apr 11, 2014
1 parent
fb6a15b
commit 1ecb3af
Showing
2 changed files
with
16 additions
and
14 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,13 @@ | |
// ============================================================================= | ||
|
||
// call the packages we need | ||
var express = require('express'); | ||
var mongoose = require('mongoose'); | ||
var app = express(); | ||
var express = require('express'); | ||
var mongoose = require('mongoose'); | ||
var bodyParser = require('body-parser'); | ||
var app = express(); | ||
|
||
// configure app | ||
app.use(bodyParser()); | ||
|
||
var port = process.env.PORT || 8080; // set our port | ||
mongoose.connect('mongodb://node:[email protected]:27017/Iganiq8o'); // connect to our database | ||
|
@@ -41,31 +45,28 @@ router.param('bear_id', function(req, res, next, id) { | |
// on routes that end in /bears | ||
router.route('/bears') | ||
// get all the bears | ||
.get(function(req, res, next) { | ||
.get(function(req, res) { | ||
res.json({ what: 'get' }); | ||
next(); | ||
}) | ||
// create a bear | ||
.post(function(req, res, next) { | ||
res.json({ what: 'post' }); | ||
next(); | ||
.post(function(req, res) { | ||
|
||
console.log(req.body); | ||
}); | ||
|
||
// on routes where we pass in a specific bear | ||
router.route('/bears/:bear_id') | ||
// get the bear with that id | ||
.get(function(req, res, next) { | ||
.get(function(req, res) { | ||
res.json({ what: req.id }); | ||
}) | ||
// update the bear with this id | ||
.put(function(req, res, next) { | ||
.put(function(req, res) { | ||
res.json({ what: 'put' }); | ||
next(); | ||
}) | ||
// delete the bear with this id | ||
.delete(function(req, res, next) { | ||
.delete(function(req, res) { | ||
res.json({ what: 'delete' }); | ||
next(); | ||
}); | ||
|
||
|
||
|