aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/utils.ts')
-rw-r--r--frontend/src/utils.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/frontend/src/utils.ts b/frontend/src/utils.ts
new file mode 100644
index 0000000..0bf115a
--- /dev/null
+++ b/frontend/src/utils.ts
@@ -0,0 +1,22 @@
+export const url = "http://localhost:8000";
+export async function postToServer(path: string, body: object, asText = false) {
+ const res = await fetch(url + path, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(body),
+ });
+ if (asText) return await res.text()
+ return res.json();
+}
+export async function fetchFromServer(path: string, asText = false) {
+ const res = await fetch(url + path);
+ if (asText) return await res.text()
+ return res.json();
+}
+export async function deleteOnServer(path: string, asText = false) {
+ const res = await fetch(url + path, { method: "DELETE" });
+ if (asText) return await res.text()
+ return res.json();
+}