juggl/juggl-server/js/api.js
2020-11-08 15:21:51 +01:00

32 lines
592 B
JavaScript

API_URL = "/api";
const api = {
getProjects() {
return request("/getProjects.php")
.then((r) => {
return r.json();
})
.then((j) => {
return j.projects;
})
.catch((e) => {
console.log(e);
return [];
});
},
};
function request(path, json = {}, options = {}) {
json.api_key = getApiKey();
json.user_id = getUserId();
options.method = "POST";
options.body = JSON.stringify(json);
options.headers = {
"Content-Type": "application/json",
};
var url = API_URL + path;
return fetch(url, options);
}