mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
31 lines
620 B
JavaScript
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')
|
|
},
|
|
}
|
|
}
|
|
})()
|