httpPut
Makes a PUT
request to the passed URL.
- Use
XMLHttpRequest
web api to make aPUT
request to the givenurl
. - Set the value of an
HTTP
request header withsetRequestHeader
method. - Handle the
onload
event, by running the providedcallback
function. - Handle the
onerror
event, by running the providederr
function. - Omit the last argument,
err
to 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);
};