feat: project scaffolding - SPA shell, dark theme CSS, hash router, API client
Dieser Commit ist enthalten in:
Commit
28150c2e1c
4 geänderte Dateien mit 462 neuen und 0 gelöschten Zeilen
24
edu/js/api.js
Normale Datei
24
edu/js/api.js
Normale Datei
|
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
var API = {
|
||||
base: '/api',
|
||||
|
||||
request: function(method, path, body) {
|
||||
var opts = {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin'
|
||||
};
|
||||
if (body) opts.body = JSON.stringify(body);
|
||||
return fetch(this.base + path, opts).then(function(resp) {
|
||||
return resp.json().then(function(data) {
|
||||
if (!resp.ok) throw { status: resp.status, message: data.error || 'Fehler' };
|
||||
return data;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
get: function(path) { return this.request('GET', path); },
|
||||
post: function(path, body) { return this.request('POST', path, body); },
|
||||
del: function(path) { return this.request('DELETE', path); }
|
||||
};
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren