Skip to content

Instantly share code, notes, and snippets.

@mpj
Last active July 10, 2017 16:08
Show Gist options
  • Save mpj/32cf7670f9210aa96319611bffef0635 to your computer and use it in GitHub Desktop.
Save mpj/32cf7670f9210aa96319611bffef0635 to your computer and use it in GitHub Desktop.
function £http(method, uri, body) {
let opts = {
mode: 'cors',
method: method,
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': getCookieValue('XSRF-TOKEN')
}
}
if (body) {
opts.body = JSON.stringify(body)
}
return fetch(uri, opts ).then(response => {
return response.json().then(data => {
if (response.ok) {
return data;
} else {
return Promise.reject({status: response.status, data});
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment