aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/utils.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-03-10 15:39:25 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-03-10 15:39:25 +0100
commit58e1ffa9effc92f5ddebee4068d5931be12201b0 (patch)
tree45b3fb1e652c7ec72e486fb9c21b1fda0deb7db9 /frontend/src/utils.ts
downloadбібліотека-58e1ffa9effc92f5ddebee4068d5931be12201b0.tar.gz
бібліотека-58e1ffa9effc92f5ddebee4068d5931be12201b0.tar.zst
бібліотека-58e1ffa9effc92f5ddebee4068d5931be12201b0.zip
Initial commit w/ v1.0.0
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();
+}