-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
56 lines (48 loc) · 1.06 KB
/
api.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
/*
* Serve JSON to our AngularJS client
*/
// For a real app, you'd make database requests here.
// For this example, "data" acts like an in-memory "database"
var data = {
"persons": [
{
"name": "Alex",
"age": 26,
"interests": ['basketball', 'biking', 'hiking']
},
{
"name": "Boris",
"age": 27,
"interests": ['soccer', 'sailing', 'ping pong']
},
{
"name": "Brian",
"age": 35,
"interests": ['tennis', 'racing', 'robotics']
}
]
};
// GET
exports.listPersons = function (req, res) {
res.json({
persons: data.persons
});
};
// POST
exports.addPerson = function (req, res) {
var person = req.body;
// TODO: add person to persons list
res.json(true); // placeholder
};
// PUT
exports.editPerson = function (req, res) {
var id = req.params.id;
// TODO: edit person where index === id
res.json(true); // placeholder
};
// DELETE
exports.deletePerson = function (req, res) {
var id = req.params.id;
// TODO: edit person where index === id
res.json(true); // placeholder
};