aboutsummaryrefslogtreecommitdiff
path: root/static/api/rest.js
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-11-14 21:55:59 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-11-14 21:55:59 +0100
commit3f18f02d07802d1fc705a500e5978a9b3cb2e751 (patch)
tree283970a2f5a693706456b853c550eeaa669b5d72 /static/api/rest.js
parent351ad457f0ff95e20301a146b8c88a8f0f659aa1 (diff)
implement login
Diffstat (limited to 'static/api/rest.js')
-rw-r--r--static/api/rest.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/static/api/rest.js b/static/api/rest.js
new file mode 100644
index 0000000..b314615
--- /dev/null
+++ b/static/api/rest.js
@@ -0,0 +1,22 @@
+
+async function handle_fetch(promise) {
+ const result = await promise;
+ const json = await result.json();
+
+ if (!result.ok) {
+ throw json;
+ }
+
+ return json;
+}
+
+export function get(url) {
+ return handle_fetch(fetch(url));
+}
+
+export async function post(url, body) {
+ return handle_fetch(fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(body),
+ }));
+}