937 B
937 B
title, tags, expertise, cover, firstSeen, lastUpdated
| title | tags | expertise | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| HTTP delete | browser | intermediate | blog_images/beach-from-above.jpg | 2020-04-16T11:21:33+03:00 | 2020-10-19T22:49:51+03:00 |
Makes a DELETE request to the passed URL.
- Use the
XMLHttpRequestweb API to make aDELETErequest to the givenurl. - Handle the
onloadevent, by running the providedcallbackfunction. - Handle the
onerrorevent, by running the providederrfunction. - Omit the third argument,
errto log the request to the console's error stream by default.
const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest();
request.open('DELETE', url, true);
request.onload = () => callback(request);
request.onerror = () => err(request);
request.send();
};
httpDelete('https://jsonplaceholder.typicode.com/posts/1', request => {
console.log(request.responseText);
}); // Logs: {}