-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
102 lines (93 loc) · 2.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const express = require('express')
const bodyParser = require("body-parser")
const app = express()
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const port = 3000
let filmes = [
{
"title": "Avatar",
"year": 2009,
"director": "James Cameron"
},
{
"title": "I Am Legend",
"year": 2007,
"director": "Francis Lawrence"
},
{
"title": "300",
"year": 2006,
"director": "Zack Snyder"
},
{
"title": "The Avengers",
"year": 2012,
"director": "Joss Whedon"
}
]
let livros = [
{
"author": "Chinua Achebe",
"country": "Nigeria",
"pages": 209,
"title": "Things Fall Apart",
"year": 1958
},
{
"author": "Hans Christian Andersen",
"country": "Denmark",
"pages": 784,
"title": "Fairy tales",
"year": 1836
},
{
"author": "Dante Alighieri",
"country": "Italy",
"pages": 928,
"title": "The Divine Comedy",
"year": 1315
},
{
"author": "Unknown",
"country": "Sumer and Akkadian Empire",
"pages": 160,
"title": "The Epic Of Gilgamesh",
"year": -1700
},
{
"author": "Unknown",
"country": "Achaemenid Empire",
"pages": 176,
"title": "The Book Of Job",
"year": -600
},
{
"author": "Unknown",
"country": "India/Iran/Iraq/Egypt/Tajikistan",
"pages": 288,
"title": "One Thousand and One Nights",
"year": 1200
}
]
app.get('/movies', (req, res) => {
res.send(filmes)
})
app.post('/movies', (req, res) => {
filme = req.body
filmes.push(filme)
res.status(201)
res.send(filmes)
})
app.get('/livros', (req, res) => {
res.send(livros)
})
app.post('/livros', (req, res) => {
livro = req.body
livros.push(livro)
res.status(201)
res.send(livros)
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})