I am trying to make an update to a specific attribute in a JSON object by using the fetch PUT method. I have set up a put function that takes in 2 URL parameters
app.put('/trustRoutes/:id/:item', (req, res){
So far, I have been able to update the data with a single parameter. However, the issue arises when I attempt to update just one value within the object. When I call the PUT method, it ends up replacing the entire object with the new body information.
Below is the code snippet that I have tried.
app.put('/trustRoutes/:id/:item', (req, res) => {
readFile(data => {
const userId = req.params['id/item'];
// I have also attempted const userId = req.params.id.item
data[userId] = req.body;
//write data back to file
I have looked at other examples, but most of them focus on data retrieval using GET requests. If there are any examples that address data updating that I might have missed, please feel free to inform me.