Random Quote Fetcher from API

  • Share this:

Code introduction


This function fetches a random quote from the API at https://api.quotable.io/random.


Technology Stack : Requests

Code Type : Function

Code Difficulty : Intermediate


                
                    
import requests
import random

def fetch_random_quote():
    url = "https://api.quotable.io/random"
    response = requests.get(url)
    if response.status_code == 200:
        return response.json()['content']
    else:
        return "Failed to fetch quote"

# JSON Explanation                
              
Tags: