Skip to content

Commit

Permalink
Merge pull request #2437 from Mod8124/main
Browse files Browse the repository at this point in the history
Reto #10 - typescript
  • Loading branch information
Roswell468 authored Mar 7, 2023
2 parents 7af7dc8 + 7cb71c3 commit 028cd8c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Retos/Reto #10 - LA API [Media]/typescript/Mod8124.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Llamar a una API es una de las tareas más comunes en programación.
//
// Implementa una llamada HTTP a una API (la que tú quieras) y muestra su
// resultado a través de la terminal. Por ejemplo: Pokémon, Marvel...

const URLQUOTE: string = 'https://quote-garden.onrender.com/api/v3/quotes';

const getQuote = async (calls: number = 0): Promise<void> => {

if (calls === 3) return console.log('Reaching 3 max calls to the API quote');
try {
const request = await fetch(URLQUOTE);
const response = await request.json();

if (response.statusCode !== 200) throw new Error('Failed API call');
const { data } = response;
console.log(data);

} catch (err) {
console.log(err.message);
getQuote(calls + 1);

}
};

getQuote();

0 comments on commit 028cd8c

Please sign in to comment.