Skip to content

Commit

Permalink
getting data from the post
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sevilleja committed Apr 11, 2014
1 parent fb6a15b commit 1ecb3af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"express": "~4.0.0",
"morgan": "~1.0.0",
"mongoose": "~3.6.13"
"mongoose": "~3.6.13",
"body-parser": "~1.0.1"
}
}
27 changes: 14 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});


Expand Down

0 comments on commit 1ecb3af

Please sign in to comment.