app.get('/students', (req, res) => {
res.json(students);
});
app.post('/students', (req, res) => {
const newStudent = req.body;
students.push(newStudent);
res.status(201).json(newStudent);
});
app.put('/students/:id', (req, res) => {
const id = parseInt(req.params.id);
const index = students.findIndex(student => student.id === id);
if (index !== -1) {
students[index] = { ...students[index], ...req.body };
res.json(students[index]);
} else {
res.status(404).send('Student not found');
}
});
app.delete('/students/:id', (req, res) => {
const id = parseInt(req.params.id);
students = students.filter(student => student.id !== id);
res.status(204).send();
});