Created
December 13, 2025 18:13
-
-
Save davidystephenson/56a5c2324f8051fe3001d6ceb78dcf99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getProducts () { | |
| const tbody = document.querySelector('tbody') | |
| const response = await fetch('http://localhost:3000/products') | |
| const data = await response.json() | |
| console.log('data', data) | |
| /* | |
| category: "Bags" | |
| description: "Everyday bag with padded sleeved for Laptop" | |
| id: "1c66" | |
| image: "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg" | |
| isAvailable: "Yes" | |
| name: "Foldsack Backpack" | |
| price: 109.95 | |
| quantity: 10 | |
| */ | |
| for (const product of data) { | |
| tbody.innerHTML += ` | |
| <tr> | |
| <td>${product.id}</td> | |
| <td>${product.name}</td> | |
| <td>${product.price}</td> | |
| <td>${product.description}</td> | |
| <td>${product.quantity}</td> | |
| <td>${product.category}</td> | |
| <td>${product.available}</td> | |
| <td> | |
| <img src="${product.image}" width="100" /> | |
| </td> | |
| <td></td> | |
| </tr> | |
| ` | |
| } | |
| } | |
| getProducts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment