aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/backend.js
blob: 35ae6e3a2ea9a7dc6c9e46ea2af21804feb78c36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
async function request(method, url, data) {
    const options = {
        method: method,
        mode: "cors",
        cache: "no-cache",
        credentials: "same-origin",
        headers: {
            "Content-Type": "application/json"
        },
        redirect: "follow",
        referrerPolicy: "no-referrer",
    };
    if (data != null) {
        options.body = JSON.stringify(data);
    }
    const result = await fetch(url, options);
    return result.json();
}

const backend = {
    get: (url = "") => {
        return request("GET", url, null);
    },
    post: (url = "", data = null) => {
        return request("POST", url, data);
    },
    put: (url = "", data = null) => {
        return request("PUT", url, data);
    },
    delete: (url = "", data = null) => {
        return request("DELETE", url, data);
    }
};

export default backend;