function get() { return { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, } } function post(data) { return { method: 'POST', body: JSON.stringify(data), headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, } } function postBody(data) { return { method: 'POST', headers: { 'Accept': 'application/json', }, body: data, } } function put(data) { return { method: 'PUT', body: data, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, } } function error(err) { console.warn(err) } export default { folder: { index: () => { return fetch('/folders/') .then(req => req.json()) .catch(error) }, show: (id) => { return fetch('/folders/' + id) .then(req => req.json()) .catch(error) }, create: (data) => { return fetch('/folders/new', post(data)) .then(req => req.json()) .catch(error) }, update: (data) => { return fetch('/folders/' + data.id, put(data)) .then(req => req.json()) .catch(error) }, }, file: { upload: (folder_id, files) => { var data = new FormData() for (var i = 0; i < files.length; i++) { data.append('file', files[i]) } return fetch('/folders/' + folder_id, postBody(files)) .then(req => req.json()) .catch(error) }, }, }