-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.js
1 lines (1 loc) · 1.52 KB
/
modules.js
1
let urlInput=document.getElementById("url"),requestTypeSelect=document.querySelector("#requestType"),bodyInput=document.getElementById("requestJsonText"),responseContainer=document.getElementById("JSONresponse"),reqs=[{type:"GET",uri:"module/list",body:"NA"},{type:"POST",uri:"module/create",body:JSON.stringify({code:"123456-ABCD123",title:"module title"},null,4)},{type:"GET",uri:"module/{m_id}/assessment/list",body:"NA"},{type:"POST",uri:"module/{m_id}/assessment/create",body:JSON.stringify({type:"classtest",description:"assessment description",weight:30},null,4)},{type:"PUT",uri:"module/{m_id}/assessment/{a_id}/update",body:JSON.stringify({type:"performance",description:"update assessment description",weight:10},null,4)},{type:"DELETE",uri:"assessment/{a_id}/delete",body:"NA"}];function setRequestTemplate(e){urlInput.value=window.location.origin+"/~sgschene/v1/"+reqs[e].uri,requestTypeSelect.value=reqs[e].type,bodyInput.value=reqs[e].body}let submit=document.getElementById("submit");submit.addEventListener("click",async()=>{responseContainer.innerText="Fetching response...";var e=urlInput.value,t=requestTypeSelect.value,s=bodyInput.value;if("GET"==t||"DELETE"==t){const i=await fetch(e,{method:t});var n=await i.json();responseContainer.innerText=i.status+" "+i.statusText+"\n"+JSON.stringify(n,null,4)}else if("POST"==t||"PUT"==t){const u=await fetch(e,{method:t,body:s,headers:{"Content-type":"application/json; charset=UTF-8"}});n=await u.json();responseContainer.innerText=u.status+" "+u.statusText+"\n"+JSON.stringify(n,null,4)}});