Now that you understand REST and database integration, let’s bring it all together in a mini-project: a Task Manager API that supports full CRUD operations (Create, Read, Update, Delete).
📦 Project Setup
Task Schema:
idtitlecompleted
⚙️ Node.js CRUD API Example (MongoDB)
Update Task
app.put('/tasks/:id', async (req, res) => {
await Task.findByIdAndUpdate(req.params.id, req.body);
res.send('Task updated');
});
Delete Task
app.delete('/tasks/:id', async (req, res) => {
await Task.findByIdAndDelete(req.params.id);
res.send('Task deleted');
});
⚙️ PHP CRUD API Example (MySQL)
Update
parse_str(file_get_contents("php://input"), $_PUT);
$stmt = $mysqli->prepare("UPDATE tasks SET title=?, completed=? WHERE id=?");
$stmt->bind_param("sii", $_PUT['title'], $_PUT['completed'], $_GET['id']);
$stmt->execute();
Delete
parse_str(file_get_contents("php://input"), $_DELETE);
$stmt = $mysqli->prepare("DELETE FROM tasks WHERE id=?");
$stmt->bind_param("i", $_GET['id']);
$stmt->execute();
🚀 Conclusion
By the end of this project, you:
- Built RESTful routes for CRUD operations
- Integrated with MongoDB (Node.js) or MySQL (PHP)
- Created a working backend system
👉 This foundation sets you up to build full-stack apps with frontend frameworks like React or even mobile apps that talk to your API.
