-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI Module
More file actions
23 lines (22 loc) · 706 Bytes
/
Copy pathAPI Module
File metadata and controls
23 lines (22 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* @file api.js
* @description A module for fetching data. In this project, it fetches from a local JSON file.
*/
export const API = {
/**
* Fetches the main application data from data.json.
* @returns {Promise<Object|null>} A promise that resolves to the parsed JSON data, or null on error.
*/
async fetchData() {
try {
const response = await fetch('data.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error("Could not fetch data:", error);
return null;
}
}
};