diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/api.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils/api.js b/src/utils/api.js new file mode 100644 index 0000000..1f8e92d --- /dev/null +++ b/src/utils/api.js @@ -0,0 +1,32 @@ +const API_URL = 'http://localhost:5000'; // Replace with your actual API URL + +export const fetchAds = async () => { + try { + const response = await fetch(`${API_URL}/ads`); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return await response.json(); + } catch (error) { + console.error('Error fetching ads:', error); + return []; + } +}; + +export const addAd = async (ad) => { + try { + const response = await fetch(`${API_URL}/ads`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(ad), + }); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return await response.json(); + } catch (error) { + console.error('Error adding ad:', error); + } +}; |