widuri-client/js/voy.js

13 lines
437 B
JavaScript

async function voy(url, method, data = null, contentType, authorization) {
const headers = { "Content-Type": contentType };
if (authorization) headers.Authorization = authorization;
const body =
data && contentType === "application/json" ? JSON.stringify(data) : data;
return await fetch(url, { method, headers, body }).then((res) => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
});
}