fetchbee
Version:
A lightweight JS library to simplify all kinds of API calls.
33 lines (25 loc) • 762 B
JavaScript
async function getWithDate(baseUrl, from, to, options = {}) {
if (!baseUrl || typeof baseUrl !== "string") {
console.warn("Invalid or missing baseUrl in getWithDate.");
return null;
}
const { page, size, ...restOptions } = options;
const query = {
...(restOptions.query || {}),
};
if (from) query.from = from;
if (to) query.to = to;
if (typeof page === "number") query.page = page;
if (typeof size === "number") query.size = size;
return getFetch(baseUrl, {
...restOptions,
query,
});
}
// getWithDate("http://localhost:1201/api/logs", "2025-06-01", "2025-06-30", {
// page: 1,
// size: 20,
// headers: {
// Authorization: `Bearer ${sessionStorage.getItem("authToken")}`
// }
// }).then(console.log);