Random Quote Fetcher from Quotable.io

  • Share this:

Code introduction


This function fetches a random quote from quotable.io API and returns the quote.


Technology Stack : Requests, JSON

Code Type : Function

Code Difficulty : Intermediate


                
                    
import requests
import json
from random import choice

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