To delete an external resource from your front-end application you can make use of the Fetch API. The implementation is very as simple as providing the "endpoint URL" as the 1st parameter and an object with the configuration/details which is necessary.
DELETE Resource with Fetch API Code Example
For the example, we'll be calling the "JSONPlaceholder" which is a fake API for testing and the endpoint will be the following.https://jsonplaceholder.typicode.com/posts/1
The full code will be like below. Do note that the resource will not be really updated on the server but it will be faked as if.
fetch('https://jsonplaceholder.typicode.com/posts/1', {
method: 'DELETE',
});
Leave a reply