Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const express = require('express');
const app = express();

const students = [
{ id: "28-09121", name: "Omar Sherif", github_username: "osheriff", email: "omarr@whatever.com" },
{ id: "21-094123", name: "Mathew White", github_username: "matheww", email: "matheww@whatever.com" },
{ id: "15-10312", name: "Dom Sundle", github_username: "domss", email: "domss.whatever.com" },
{ id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "gehad.ismail@guc.edu.eg" },
{id:"40-1979", name:"Abdelrahman Abodeif" , github_username:"ZizoAbudeif" , email:"aboudyadel007@gmail.com"}
];

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}`));
5 changes: 3 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const students = [
{ id: "28-09121", name: "Omar Sherif", github_username: "osheriff", email: "omarr@whatever.com" },
{ id: "21-094123", name: "Mathew White", github_username: "matheww", email: "matheww@whatever.com" },
{ id: "15-10312", name: "Dom Sundle", github_username: "domss", email: "domss.whatever.com" },
{ id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "gehad.ismail@guc.edu.eg" }
{ id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "gehad.ismail@guc.edu.eg" },
{ id: "40-1616", name: "Ahmed Amr", github_username: "3amoora", email: "ahmed.amr.seif@gmail.com" }
];

app.get('/', (request, response) => {
Expand Down Expand Up @@ -34,4 +35,4 @@ app.get('/api/students/:id', (request, response) => {
});

const port = 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));
app.listen(port, () => console.log(`Listening on port ${port}`));