From 3faa66a163be316e419a051dff87f48fd15864cd Mon Sep 17 00:00:00 2001 From: morningkaya <47509824+morningkaya@users.noreply.github.com> Date: Sun, 17 Feb 2019 00:14:06 +0200 Subject: [PATCH] Add files via upload --- index.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..330a1e4 --- /dev/null +++ b/index.js @@ -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-323", name: "Youssef Elshafei", github_username: "morningkaya", email: "elshafie.youssef@gmail.com" } +]; + +app.get('/', (request, response) => { + response.send(`Students`); +}); + +app.get('/api/students', (request, response) => { + let data = ""; + students.forEach((value) => { + const user_id = value.id; + const user_name = value.name; + data += `${user_name}
`; + }); + 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}
Name: ${value.name}
Email: ${value.email}
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}`)); \ No newline at end of file