aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/api.js
blob: 1f8e92d1735d24e2a49ffad0d0245fb32ec5bb5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
  }
};