SAE-A2-TruthInquiry/truthseeker/static/js/api.js
2023-01-10 13:34:47 +01:00

18 lines
526 B
JavaScript

async function makeAPIRequest(endpoint, body){
return new Promise((resolve, reject)=>{
const fetchOptions = {
method: "POST",
body: new URLSearchParams(body)
}
fetch("/api/v1/"+endpoint, fetchOptions).then(resp => {
resp.json().then(jsonResp=>{
if(jsonResp["error"] == 0){
resolve(jsonResp)
}else{
reject(endpoint+": "+jsonResp["msg"])
}
});
})
})
}