Preview:
# Quotes API
from fastapi import FastAPI, Request
from slowapi.util import get_ipaddr
from slowapi.errors import RateLimitExceeded
from slowapi import Limiter, _rate_limit_exceeded_handler

import json

def get_quotes():
    return json.load(open('quotes.json', 'r'))

app = FastAPI()
limiter = Limiter(key_func = get_ipaddr)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

@app.get('/')
@limiter.limit('10/minute')
def home(request: Request):
    return {'msg': 'Hello, World'}


@app.get('/quotes')
@limiter.limit('10/minute')
def quote(request: Request):
    return get_quotes()
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter