Enabled ability to make requests to API
This commit is contained in:
parent
ba4d00b0c0
commit
a50ba6f68a
2 changed files with 21 additions and 0 deletions
5
index.html
Normal file
5
index.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<script src="/scripts/main.js"></script>
|
||||
|
||||
<button type="button" onclick="loadProducts()">Load Products</button>
|
||||
|
||||
<p id="demo"></p>
|
||||
16
scripts/main.js
Normal file
16
scripts/main.js
Normal file
|
|
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue