-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_connect.js
46 lines (41 loc) · 1.06 KB
/
api_connect.js
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
37
38
39
40
41
42
43
44
45
46
async function getRequest(url) {
const response = await fetch(url, {
method: "GET",
mode: "cors"
})
return response
}
async function postRequest(url, body) {
const response = await fetch(url, {
method: "POST",
mode: "cors",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
})
return response
}
export async function getMode() {
const response = await getRequest("https://smartswitch.gerhardadler.no/get_mode")
const json = await response.json()
return json.mode
}
export async function setMode(mode) {
const response = await postRequest("https://smartswitch.gerhardadler.no/set_mode", {
mode: mode
})
return response
}
export async function getArea() {
const response = await getRequest("https://smartswitch.gerhardadler.no/get_area")
const json = await response.json()
return json.area
}
export async function setArea(area) {
const response = await postRequest("https://smartswitch.gerhardadler.no/set_area", {
area: area
})
return response
}