Dexter Jin

Experiments09 Updated

...@@ -9,21 +9,26 @@ app.use(bodyParser.json()); ...@@ -9,21 +9,26 @@ app.use(bodyParser.json());
9 var books = new Array(); 9 var books = new Array();
10 10
11 app.get('/book/:bookId', function (req, res) { 11 app.get('/book/:bookId', function (req, res) {
12 - // Get book information 12 + var bookId = req.params.bookId;
13 - 13 + console.log(books[bookId]);
14 + res.send(books[bookId]);
14 }); 15 });
15 16
17 +app.post('/book', function (req, res) {
18 + // Create book information
19 + books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author];
20 +
21 +})
22 +
16 app.put('/book/:bookId', function (req, res) { 23 app.put('/book/:bookId', function (req, res) {
17 // Update book information 24 // Update book information
18 25
19 }) 26 })
20 -app.post('/book', function (req, res) { 27 +
21 - // Create book information
22 -})
23 28
24 app.delete('/book/:bookId', function (req, res) { 29 app.delete('/book/:bookId', function (req, res) {
25 // Delete book information 30 // Delete book information
26 31
27 }) 32 })
28 -var server = app.listen(23023); 33 +var server = app.listen(80);
29 console.log(books); 34 console.log(books);
......
...@@ -38,4 +38,4 @@ app.get('/user/:userId', auth,function (req, res) { ...@@ -38,4 +38,4 @@ app.get('/user/:userId', auth,function (req, res) {
38 // get User Information 38 // get User Information
39 res.send("OK"); 39 res.send("OK");
40 }); 40 });
41 -var server = app.listen(23023); 41 +var server = app.listen(80);
......