Lexiconga/src/js/account/helpers.js

17 lines
496 B
JavaScript
Raw Normal View History

2019-05-15 01:21:46 +02:00
export function request (data = {}, success = () => {}, error = () => {}/* , fail = () => {} */) {
return fetch('./api/', {
2019-05-13 22:02:10 +02:00
method: 'POST', // or 'PUT'
body: JSON.stringify(data), // data can be `string` or {object}!
headers: {
'Content-Type': 'application/json',
},
credentials: 'same-origin',
}).then(res => res.json())
.then(response => {
if (response.error) {
2019-05-15 01:21:46 +02:00
return error(response.data);
2019-05-13 22:02:10 +02:00
}
2019-05-15 01:21:46 +02:00
return success(response.data);
2019-05-13 22:02:10 +02:00
});
2019-05-21 20:14:00 +02:00
}