Sobes.tech
Middle

Scrivi una richiesta fetch che restituisce un elenco di prodotti. Avvolgila in una funzione separata che può essere riutilizzata.

sobes.tech AI

Risposta dell'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));