Generally, we delete data via a DELETE HTTP method on a REST API. Let's enter the following in the TypeScript playground:
fetch("https://jsonplaceholder.typicode.com/posts/1", {
method: "DELETE"
}).then(response => {
console.log(response.status);
});
So, we are requesting to delete a post with the DELETE method.
If we run the preceding code, we get 200 output to the console.
So, we've learned how to interact with a RESTful API with the native fetch function. In the next section, we'll look at doing the same with a popular open source library and understanding its benefits over fetch.