widuri-client/js/voy.js

13 lines
437 B
JavaScript
Raw Permalink Normal View History

2025-06-10 11:34:08 +07:00
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();
});
}