mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
(function() {
|
|
var api = function(method, endpoint, data) {
|
|
return fetch(endpoint, {
|
|
method: method,
|
|
headers: {'content-type': 'application/json'},
|
|
body: JSON.stringify(data),
|
|
})
|
|
}
|
|
|
|
var json = function(res) {
|
|
return res.json()
|
|
}
|
|
|
|
window.api = {
|
|
feeds: {
|
|
list: function() {
|
|
return api('get', '/api/feeds').then(json)
|
|
},
|
|
create: function(data) {
|
|
return api('post', '/api/feeds', data).then(json)
|
|
},
|
|
update: function(id, data) {
|
|
return api('put', '/api/feeds/' + id, data)
|
|
},
|
|
delete: function(id) {
|
|
return api('delete', '/api/feeds/' + id)
|
|
},
|
|
list_items: function(id) {
|
|
return api('get', '/api/feeds/' + id + '/items').then(json)
|
|
},
|
|
},
|
|
folders: {
|
|
list: function() {
|
|
return api('get', '/api/folders').then(json)
|
|
},
|
|
create: function(data) {
|
|
return api('post', '/api/folders', data).then(json)
|
|
},
|
|
update: function(id, data) {
|
|
return api('put', '/api/folders/' + id, data)
|
|
},
|
|
delete: function(id) {
|
|
return api('delete', '/api/folders/' + id)
|
|
},
|
|
},
|
|
}
|
|
})()
|