httpPut
Makes a PUT request to the passed URL.
- Use
XMLHttpRequestweb api to make aPUTrequest to the givenurl. - Set the value of an
HTTPrequest header withsetRequestHeadermethod. - Handle the
onloadevent, by running the providedcallbackfunction. - Handle the
onerrorevent, by running the providederrfunction. - Omit the last argument,
errto log the request to the console's error stream by default.
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);
};