Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 20, 2021 11:33 pm GMT

Sending DELETE Request In JS Using fetch

Sending DELETE request using then & catch

const id = 5;const deleteTodo = (todoId) => {  const url = `https://jsonplaceholder.typicode.com/posts/${todoId}`;  const method  = 'DELETE'  fetch(url,{method})  .then(response => console.log(response.status)/*200*/)  .catch(e=> console.log('something went wrong',e))};deleteTodo(id);

Sending DELETE request using async and await

const id = 5;const deleteTodo = async (todoId) => {  const url = `https://jsonplaceholder.typicode.com/posts/${todoId}`;  const method  = 'DELETE';  try {    const response = fetch(url, {method});    console.log((await response).status)// 200  }catch(e){    console.log('something went wrong', e);  }} deleteTodo(id);

Have a good day


Original Link: https://dev.to/ayabouchiha/sending-delete-request-in-js-using-fetch-293b

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To