2020-07-01 20:28:36 +01:00

31 lines
620 B
JavaScript

"use strict";
(function() {
var api = function(method, endpoint, data) {
var promise = fetch(endpoint, {
method: method,
headers: {'content-type': 'application/json'},
body: JSON.stringify(data),
})
return promise.then(function(res) {
if (res.ok) return res.json()
})
}
window.api = {
feeds: {
list: function() {
return api('get', '/api/feeds')
},
create: function(data) {
return api('post', '/api/feeds', data)
},
},
folders: {
list: function() {
return api('get', '/api/folders')
},
}
}
})()