The DELETE method is an HTTP request method used to delete a specified resource on a server. When a client sends a DELETE request to a server, it requests that the server remove the specified resource, such as a file, a database record, or any other identifiable data, from the server.
xxxxxxxxxx
const deleteData = async ( ) =>{
const response = await fetch('https://jsonplaceholder.typicode.com/posts/1', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: null
});
const data = await response.json( );
// now do whatever you want with the data
console.log(data);
};
deleteData( );
xxxxxxxxxx
fetch(YOUR_URL, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(YOUR_ADDITIONAL_DATA) //if you do not want to send any addional data, replace the complete JSON.stringify(YOUR_ADDITIONAL_DATA) with null
})
xxxxxxxxxx
const myDataObject ={ userId: 1}
fetch(YOUR_URL, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(myDataObject)
})
.then(response => {
return response.json( )
})
.then(data =>
// this is the data we get after doing the delete request, do whatever you want with this data
console.log(data)
);