From 84451e59cb33632e930bf68170fed59d97ce4502 Mon Sep 17 00:00:00 2001 From: mayarlotfe <47094704+mayarlotfe@users.noreply.github.com> Date: Sun, 10 Feb 2019 23:51:55 +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..2459b86 --- /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-10293" , name:"Mayar Lotfy"} +]; + +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