INNER CODE UNIT · TypeScript

fetchQuotes

PiyushSuthar/github-readme-quotes · src/fetcher/fetch-quotes.ts:37

export async function fetchQuotes(): Promise<ParseDataReturn> {
  const response = await axios.get(
    'https://github.com/mudroljub/programming-quotes-api/raw/master/data/quotes.json'
  );

  const data: ParseDataParams[] = response.data;

  // Validate the fetched data.
  if (!Array.isArray(data)) {
    throw new Error('Fetched data is not an array.');
  }

  // Get a random quote.
  let randQuote = randomQuote(data);

  // Parse the data and return it.
  return parseData(randQuote);
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…