github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/client/web/html/assets/mu.js (about) 1 var namespace = "micro"; 2 3 function getCookie(name) { 4 const value = `; ${document.cookie}`; 5 const parts = value.split(`; ${name}=`); 6 if (parts.length === 2) return parts.pop().split(';').shift(); 7 } 8 9 async function call(url = '', data = {}) { 10 var token = getCookie("micro-token"); 11 12 // Default options are marked with * 13 const response = await fetch(url, { 14 method: 'POST', // *GET, POST, PUT, DELETE, etc. 15 headers: { 16 'Content-Type': 'application/json', 17 'Authorization': 'Bearer ' + token, 18 'Micro-Namespace': namespace, 19 }, 20 body: JSON.stringify(data) // body data type must match "Content-Type" header 21 }); 22 return response.json(); // parses JSON response into native JavaScript objects 23 } 24