Basic PUT request

A common way to change data is via a PUT request. Let's open up the TypeScript playground and enter the following: 

fetch("https://jsonplaceholder.typicode.com/posts/1", {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
title: "Corrected post",
body: "This is corrected post about ...",
userId: 1
})
})
.then(response => {
console.log(response.status);
return response.json();
})
.then(data => console.log(data));

So, the structure of a fetch call to do an HTTP PUT is very similar to a POST request. The only difference is that we specify the method property in the options object as PUT.

If we run the preceding code, we get 200 and the updated POST object output to the console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.12.240