Random Greeting Fetcher Function

  • Share this:

Code introduction


This function fetches a random greeting from an API and returns it.


Technology Stack : requests, JSON

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import requests

def fetch_random_greeting():
    # This function fetches a random greeting from an API and returns it
    url = "https://api.quotable.io/random"
    response = requests.get(url)
    data = response.json()
    return data['content']                
              
Tags: