xxxxxxxxxx
fetch('https://reqres.in/api/users', + id {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'user'
})
})
.then(res => {
return res.json()
})
.then(data => console.log(data))
xxxxxxxxxx
fetch("URL",{
// method changes
method: 'PUT',
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 0
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
// Transform the data into json
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch((error)=> {
console.log(error);
});