Basic PATCH request

Some REST APIs offer PATCH requests, which allow us to submit changes to a portion of a resource. Let's open up the TypeScript playground and enter the following:

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

So, we are submitting a change to the title of the post with the PATCH HTTP method. If we run the preceding code, we get 200 and the updated post object output to the console.

So, that's how to PUT and PATCH using fetch. In the next section, we'll delete some data.

Get Learn React with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.