Sobes.tech
Middle

Write a fetch request that returns a list of products. Wrap it in a reusable function.

sobes.tech AI

Answer from AI

javascript async function fetchProducts() { try { const response = await fetch('/api/products'); if (!response.ok) { throw new Error(Ошибка сети: ${response.status}); } const products = await response.json(); return products; } catch (error) { console.error('Не удалось получить список продуктов:', error); return []; } }

// Использование: // fetchProducts().then(products => console.log(products));

Write a fetch request that returns a list of… - sobes.tech