aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/api.js
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 22:54:55 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 22:54:55 +0530
commit680f38b1c48c4cc5c4b34b285f68fe48217d0ab9 (patch)
tree6cb3bdbf246636625b34fec022bf6619d24f8c01 /src/utils/api.js
parent458a8c849da82adf045a40919a4a9e3aa06e1c06 (diff)
downloadadmin-panel-680f38b1c48c4cc5c4b34b285f68fe48217d0ab9.tar.gz
admin-panel-680f38b1c48c4cc5c4b34b285f68fe48217d0ab9.tar.bz2
admin-panel-680f38b1c48c4cc5c4b34b285f68fe48217d0ab9.zip
setting up login
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);
+ }
+};