const express = require('express');
const app = express();
const PORT = 3002;
app.use(express.static('public'));
// Sample data
const students = {
101: { id: 101, name: 'Alice Johnson', major: 'Computer Science', gpa: 3.8 },
102: { id: 102, name: 'Bob Smith', major: 'Information Systems', gpa: 3.5 },
103: { id: 103, name: 'Carol White', major: 'Data Science', gpa: 3.9 }
};
// Route parameter endpoint
app.get('/students/:studentId', (req, res) => {
const studentId = req.params.studentId;
const student = students[studentId];
if (student) {
res.json({
success: true,
data: student
});
} else {
res.status(404).json({
success: false,
message: `Student with ID ${studentId} not found`
});
}
});
// Get all students
app.get('/students', (req, res) => {
res.json({
success: true,
count: Object.keys(students).length,
data: Object.values(students)
});
});
app.listen(PORT, () => {
console.log(`Lab 3 server running on http://localhost:${PORT}`);
});