Home / Snippets / How to Delete Resource with the Fetch API
How to Delete Resource with the Fetch API cover

How to Delete Resource with the Fetch API

251

3 years ago

0 comments

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',
});
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this