nomilo/public/scripts/api.js

23 lines
384 B
JavaScript
Raw Normal View History

2022-04-29 02:29:10 +00:00
const baseUrl = '/api/v1';
function apiGet(url) {
2022-04-29 02:33:00 +00:00
return fetch(`${baseUrl}/${url}`)
.then(res => {
if (!res.ok) {
// do something here
throw new Error('Not ok');
}
return res.json();
2022-04-29 16:04:12 +00:00
});
2022-04-29 02:29:10 +00:00
}
function getRecords(zone) {
2022-04-29 16:04:12 +00:00
return apiGet(`zones/${zone}/records`);
2022-04-29 02:29:10 +00:00
}
export {
2022-04-29 02:33:00 +00:00
getRecords,
2022-04-29 02:29:10 +00:00
};