김대휘

First commit

1 +node_modules
2 +package-lock.json
3 +yarn.lock
...\ No newline at end of file ...\ No newline at end of file
1 +var express = require('express');
2 +var app = express();
3 +var bodyParser = require('body-parser');
4 +app.use(bodyParser.urlencoded({
5 + extended: false
6 +}));
7 +app.use(bodyParser.json());
8 +var books = new Array();
9 +
10 +
11 +app.get('/books/:bookId', function (req, res) {
12 + var bookId = req.params.bookId;
13 + console.log(books[bookId]);
14 + res.send(books[bookId]);
15 +});
16 +/*
17 + * json representation of book object
18 +{
19 + "id" : 2,
20 + "name" : "book2",
21 + "price" : 2000,
22 + "author" : "jin"
23 +}
24 +*/
25 +app.post('/books', function (req, res) {
26 + // Create book information
27 + books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author];
28 + res.send(books[req.body.id]);
29 +})
30 +
31 +app.put('/books', function (req, res) {
32 + books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author];
33 + res.send(books[req.body.id]);
34 +})
35 +app.delete('/books/:bookId', function (req, res) {
36 + var index = req.param('bookId');
37 + console.log(index);
38 + if (index > -1) {
39 + books.splice(index, 1);
40 + }
41 + res.send(req.param('bookId'));
42 +})
43 +
44 +var server = app.listen(80);
45 +console.log(books);
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "dependencies": {
3 + "express": "^4.17.1"
4 + }
5 +}