Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding my name #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: "[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-7106",name:"Nadin El-Hanafy", github_username: "Nadin-ElHanafy",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}`));