aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/utils.ts
blob: 0bf115acca8e9478fc806a7094cd514c338dfdcb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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();
}