Kebab file names

This commit is contained in:
Angelos Chalaris
2023-04-27 21:58:35 +03:00
parent 1d189c709a
commit 61200d90c4
440 changed files with 0 additions and 0 deletions

30
snippets/http-delete.md Normal file
View File

@ -0,0 +1,30 @@
---
title: HTTP delete
tags: browser
cover: beach-from-above
firstSeen: 2020-04-16T11:21:33+03:00
lastUpdated: 2020-10-19T22:49:51+03:00
---
Makes a `DELETE` request to the passed URL.
- Use the `XMLHttpRequest` web API to make a `DELETE` request to the given `url`.
- Handle the `onload` event, by running the provided `callback` function.
- Handle the `onerror` event, by running the provided `err` function.
- Omit the third argument, `err` to log the request to the console's error stream by default.
```js
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();
};
```
```js
httpDelete('https://jsonplaceholder.typicode.com/posts/1', request => {
console.log(request.responseText);
}); // Logs: {}
```