From 58e1ffa9effc92f5ddebee4068d5931be12201b0 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Thu, 10 Mar 2022 15:39:25 +0100 Subject: Initial commit w/ v1.0.0 --- frontend/src/utils.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 frontend/src/utils.ts (limited to 'frontend/src/utils.ts') 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(); +} -- cgit v1.3.1