You can download this code by clicking the button below.
This code is now available for download.
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']