forked from SE-GUC/Task1-ENG-10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (33 loc) · 1.46 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
const express = require('express');
const app = express();
const students = [
{ id: "28-09121", name: "Omar Sherif", github_username: "osheriff", email: "[email protected]" },
{ id: "21-094123", name: "Mathew White", github_username: "matheww", email: "[email protected]" },
{ id: "15-10312", name: "Dom Sundle", github_username: "domss", email: "domss.whatever.com" },
{ id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "[email protected]" },
{ id: "40-876", name: "Nada Labib", github_username: "NadaLabib", email: "[email protected]" }
];
app.get('/', (request, response) => {
response.send(`<a href="/api/students">Students</a>`);
});
app.get('/api/students', (request, response) => {
let data = "";
students.forEach((value) => {
const user_id = value.id;
const user_name = value.name;
data += `<a href="/api/students/${user_id}">${user_name}</a><br>`;
});
response.send(data);
});
app.get('/api/students/:id', (request, response) => {
var data = "";
students.forEach((value) => {
if(value.id === request.params.id) {
data = `Id: ${value.id}<br>Name: ${value.name}<br>Email: ${value.email}<br>Github: ${value.github_username}`;
return;
}
});
response.send(data || 'No student matches the requested id');
});
const port = 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));