fetchbee
Version:
A lightweight JS library to simplify all kinds of API calls.
15 lines (12 loc) • 392 B
JavaScript
import { buildUrl } from "./helpers/buildUrl.js";
export async function getFetch(url, options = {}) {
const response = await fetch(buildUrl(url, options.query || {}), {
method: "GET",
headers: {
"Content-Type": "application/json",
...options.headers,
},
});
if (!response.ok) throw new Error(`GET Error: ${response.status}`);
return await response.json();
}