diff options
Diffstat (limited to 'src/utils/api.js')
-rw-r--r-- | src/utils/api.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils/api.js b/src/utils/api.js new file mode 100644 index 0000000..7b63aa4 --- /dev/null +++ b/src/utils/api.js @@ -0,0 +1,21 @@ +export const fetchAds = async () => { + const response = await fetch('http://localhost:5000/ads'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); +}; + +export const addAd = async (ad) => { + const response = await fetch('http://localhost:5000/ads', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(ad), + }); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); +}; |