You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects one of the three APIs and fetches a random quote and author. It uses the requests library to send HTTP requests and parse JSON responses.
Technology Stack : requests, JSON
Code Type : Python Function
Code Difficulty : Intermediate
import random
import requests
def fetch_random_greeting():
urls = [
"https://api.quotable.io/random",
"https://api.quotable.io/random",
"https://api.quotable.io/random"
]
response = requests.get(random.choice(urls))
data = response.json()
return f"{data['content']} - {data['author]}"
# JSON Explanation