aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/api.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/api.js')
-rw-r--r--src/utils/api.js32
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);
+ }
+};