Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/56a5c2324f8051fe3001d6ceb78dcf99 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/56a5c2324f8051fe3001d6ceb78dcf99 to your computer and use it in GitHub Desktop.
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