From a50ba6f68afbcf768511e98a7a2a654c434a23e9 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Sun, 4 Aug 2024 10:19:24 +0200 Subject: [PATCH] Enabled ability to make requests to API --- index.html | 5 +++++ scripts/main.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 index.html create mode 100644 scripts/main.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..b534314 --- /dev/null +++ b/index.html @@ -0,0 +1,5 @@ + + + + +

\ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js new file mode 100644 index 0000000..dcf0000 --- /dev/null +++ b/scripts/main.js @@ -0,0 +1,16 @@ +async function makeAPIRequest(request) { + try { + const response = await fetch(request); + const result = await response.json(); + return result + } catch (error) { + console.error("Error:", error); + } +} + +async function loadProducts() { + const loadProductRequest = new Request("http://127.0.0.1:8000/products") + const result = await makeAPIRequest(loadProductRequest) + console.log(result) + } + \ No newline at end of file