-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.js
50 lines (43 loc) · 1.04 KB
/
backend.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
47
48
49
50
import nodeFetch from "node-fetch"
async function getFromPath(path) {
const endpoint = `http://localhost:8080${path}`
const req = {
method: "GET",
headers: {
Accept: "application/json"
},
}
const res = await nodeFetch(endpoint, req)
return res.json()
}
async function postToPath(path, data) {
const endpoint = `http://localhost:8080${path}`
const req = {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(data)
}
const res = await nodeFetch(endpoint, req)
return res.json()
}
async function loadSchema(itemType) {
return await getFromPath(`/schema/${itemType}`)
}
async function listIds(itemType) {
return await getFromPath(`/listids/${itemType}`)
}
async function loadItem(itemType, itemId) {
return await getFromPath(`/load/${itemType}/${itemId}`)
}
async function saveItem(itemType, itemData) {
return await postToPath(`/save/${itemType}`, itemData)
}
export default {
loadSchema,
listIds,
loadItem,
saveItem
}