diff --git a/snippets/httpDelete b/snippets/httpDelete new file mode 100644 index 000000000..e69de29bb diff --git a/snippets/httpPut.md b/snippets/httpPut.md index 6946b6ff1..34a42d5df 100644 --- a/snippets/httpPut.md +++ b/snippets/httpPut.md @@ -1,28 +1,24 @@ -### httpPost +### httpDelete -Makes a `PUT` request to the passed URL. +Makes a `DELETE` request to the passed URL. -Use `XMLHttpRequest` web api to make a `put` request to the given `url`. -Set the value of an `HTTP` request header with `setRequestHeader` method. +Use `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 last argument, `err` to log the request to the console's error stream by default. +Omit the third argument, `err` to log the request to the console's error stream by default. ```js -const httpPut = (url, data, callback, err = console.error) => { - const request = new XMLHttpRequest(); - request.open("PUT", url, true); - request.setRequestHeader('Content-type','application/json; charset=utf-8'); - request.onload = () => callback(request); - request.onerror = () => err(request); - request.send(data); +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 -const password = "fooBaz"; -const data = JSON.stringify(password); -httpPost(`https://website.com/users/123`, data, request => { +httpDelete('https://website.com/users/123', request => { console.log(request.responseText); -}); // 'Updates a user's password in database' +}); // 'Deletes a user from the database' ```