Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 4, 2025 17:03
Show Gist options
  • Save thinkphp/d208fad30a8284e2b986e776cc8dae34 to your computer and use it in GitHub Desktop.
Save thinkphp/d208fad30a8284e2b986e776cc8dae34 to your computer and use it in GitHub Desktop.
functie asyncrona
async function obtineDateUtilizator(idUtilizator) {
try {
// Folosim fetch pentru a face cererea
const raspuns = await fetch(`https://jsonplaceholder.typicode.com/users/${idUtilizator}`);
// Convertim răspunsul în format JSON
const date = await raspuns.json();
// Afișăm datele utilizatorului
console.log('Date utilizator:', date);
return date;
} catch (eroare) {
// Gestionăm orice erori care pot apărea
console.error('A apărut o eroare:', eroare);
}
}
// Apelăm funcția
obtineDateUtilizator(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment