I want to send a put request to modify the command part of my JSON file. Here is my JSON;
{
"users": [
{
"hostname": "xxx.xxx.xxx.xx",
"password": "password1",
"command": "command1",
"id": 1
},
{
"hostname": "xxx.xxx.xxx.xx",
"password": "password2",
"command": "command2",
"id": 2
},
{
"hostname": "xxx.xx.xx.xxx",
"password": "password3",
"command": "command3",
"id": 3
}
]
}
In App.js I send put request like this;
stopPC(id){
axios.put('http://localhost:3002/users/'+id,{
command: 'stop'
})
}
And I have tried this;
axios({
method: 'put',
url: 'http://localhost:3002/users/'+ id,
data: {
hostname: id.hostname,
password: id.password,
command: 'stop'
}
});
In both, I got the following output in the JSON file.
{
"users": [
{
"command": "stop",
"id": 1
},
{
"hostname": "xxx.xxx.xxx.xx",
"password": "password2",
"command": "command2",
"id": 2
},
{
"hostname": "xxx.xxx.xxx.xx",
"password": "password3",
"command": "command3",
"id": 3
}
]
}
I want to change only the command information while keeping the hostname and password information the same.
I'm not sure where I went wrong, I'd be glad if you could help.