thedesk/app/js/common/api.js

38 lines
1004 B
JavaScript
Raw Normal View History

2020-07-10 23:33:12 +10:00
async function getApi(start, at) {
2020-07-10 15:16:39 +10:00
let json = {}
let response = null
response = await fetch(start, {
method: 'GET',
headers: {
2020-07-10 23:33:12 +10:00
'content-type': 'application/json',
'Authorization': `Bearer ${at}`
2020-07-10 15:16:39 +10:00
}
})
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
json = await response.json()
return json
2020-07-10 23:33:12 +10:00
}
async function postApi(url, body, at, ideKey) {
let json = {}
let response = null
response = await fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${at}`,
'Idempotency-Key': ideKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
json = await response.json()
return json
2020-07-10 15:16:39 +10:00
}