From 680f38b1c48c4cc5c4b34b285f68fe48217d0ab9 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 22:54:55 +0530 Subject: setting up login --- src/utils/api.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/utils/api.js (limited to 'src/utils/api.js') 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); + } +}; -- cgit v1.2.3-59-g8ed1b