This content originally appeared on DEV Community and was authored by Aya Bouchiha
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
This content originally appeared on DEV Community and was authored by Aya Bouchiha
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Aya Bouchiha | Sciencx (2021-08-20T23:33:04+00:00) Sending DELETE Request In JS Using fetch. Retrieved from https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/
" » Sending DELETE Request In JS Using fetch." Aya Bouchiha | Sciencx - Friday August 20, 2021, https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/
HARVARDAya Bouchiha | Sciencx Friday August 20, 2021 » Sending DELETE Request In JS Using fetch., viewed ,<https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/>
VANCOUVERAya Bouchiha | Sciencx - » Sending DELETE Request In JS Using fetch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/
CHICAGO" » Sending DELETE Request In JS Using fetch." Aya Bouchiha | Sciencx - Accessed . https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/
IEEE" » Sending DELETE Request In JS Using fetch." Aya Bouchiha | Sciencx [Online]. Available: https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/. [Accessed: ]
rf:citation » Sending DELETE Request In JS Using fetch | Aya Bouchiha | Sciencx | https://www.scien.cx/2021/08/20/sending-delete-request-in-js-using-fetch/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.