Understanding Rate Limits

What I’m trying to do:

I’m just playing with the REST API for theysaidso.com which has a rate limit of 10 requests per hour unless you subscribe. I reached that limit on a desktop version of my app but was pleased to see when I ported it as a toy Anvil app I got another 10 requests to play with.

I’m not trying to circumvent the limit so much as understand from a newbie perspective where the requests are now coming from… For example is there a central Anvil server making those requests from the same IP address, with that server is now limited to 10 requests/hour, or is there a cloud computing back end, or are the requests coming from the client side? It would be nice if the latter were true, as I assume then I could have many different users of my app (and apps like it) EACH limited to 10 requests/hour.

If I really needed to, is there another way of me making the GET request through Anvil but through a proxy server?

This isn’t an urgent request for help, I’m just keen to know what’s going on “under the bonnet” and whether I have any options for managing that… Thanks!

What I’ve tried and what’s not working:

I’ve added error handling so you should just see this until the hourly limit resets each time:

Server Code:

import anvil.server
from random import choice
import requests
import json

@anvil.server.callable
def get_quote(category=None):
  """
  Returns a nicely formatted Quote of the Day from theysaidso.com.
  If no category is specified, pick one at random.

  For unregistered use there is a limit of 10 requests per hour.
  """
  if category is None:
      category = choice(["management", "inspire", "life", "funny", "love", "sports",])
  url = f"http://quotes.rest/qod.json?category={category}"
  try:
    quote = json.loads(requests.get(url).text)['contents']['quotes'][0]
    text = f"\"{quote['quote']}\" ({quote['author']})"
    image_link = quote['background']
    tags = quote['tags']
  except KeyError:
    quote ="Error - probably exceeded 10 requests per hour"
    image_link="https://media.giphy.com/media/KHKGN7BUO3zsaQWC46/giphy.gif"
    tags=["ratelimited"]
  return text, image_link, tags

Clone link:
https://anvil.works/build#clone:FJ45YH55JIJGRXCN=VC3CUFAIMSUFU4AKW73DCLP2

just a quick tip - you can use anvil.http.request(url, json=True) on the client as well as on the server.

2 Likes

Thanks @stucork - I’ll give that a go and see what I learn!