Random Greeting Fetcher Function

  • Share this:

Code introduction


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


Technology Stack : The requests library is used to send HTTP requests to fetch the API response.

Code Type : Python 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']

# JSON Explanation