-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 921 Bytes
/
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
const express = require("express");
const app = express();
const user_data = require("./MOCK_DATA.json");
const port =9000;
// routes:>
app.get("/users", (req, res) => {
const html = `
<ul>
${user_data.map(user_data => `<li>${user_data.first_name + user_data.id}</li>`).join('')}
</ul>
`;
return res.send(html);
});
app.get("/api/users",(req,res)=>{
return res.json(user_data);
});
app.route("/api/users/:id")
.get((req,res)=>{
const id= Number(req.params.id);
const user = user_data.find((user)=> user.id ===id);
return res.json(user);
})
.patch( (req,re)=>{
return res.json({status:'pending!'});
})
.delete( (req,re)=>{
return res.json({status:'pending!'});
});
app.post("/api/users" , (req,re)=>{
return res.json({status:'pending!'});
});
app.listen(port ,()=>{
console.log("server started :)");
} )