| Semester_4 |
|---|
| 01_Introduction |
| 02_DeployAzure |
| 03_JSBasic |
| 04_OOP |
| 05_GET |
| 06_POST |
| 07_PUT |
| 08_PATCH |
| 09_DELETE |
| 10_FrontendTable |
| 11_FrontendAdd |
| 12_FrontendDelete |
| 13_FrontendEdit |
| 14_Database |
In REST, PATCH is an HTTP method used to partially update an existing resource — meaning, you only change some fields instead of replacing the entire record.
| Method | Purpose | Description |
|---|---|---|
| GET | Read | Retrieve data |
| POST | Create | Add a new resource |
| PUT | Replace | Update all fields (full update) |
| PATCH | Modify | Update specific fields (partial update) |
| DELETE | Remove | Delete a resource |
// **NEW** Partially update a Student
app.patch("/students/:id", (req, res) => {
const id = parseInt(req.params.id);
const { name, course } = req.body;
const student = students.find(s => s.id === id);
if (!student) {
return res.status(404).json({ error: "Student not found" });
}
if (name !== undefined) student.name = name;
if (course !== undefined) student.course = course;
res.json(student);
});curl -X PATCH http://localhost:3000/students/4 \
-H "Content-Type: application/json" \
-d '{"course":"Statistics"}'Do not forget
Deploy