Requests are rate limited to prevent a single user from monopolising the resources.
Response headers show we are allowed 55000 requests over an hour (3600 seconds): an average 15 requests per second.
This script queries the ping endpoint 25 times, printing the count, the HTTP Status Code, and the X-RateLimit-Remaining header each time.
1. Increase the number of loops, do you start to get 429 errors?
2. Can you add in a step to make it wait a few seconds every iteration? Or every 100 iterations?
# Exercise 7.1
library(httr)
server <- "http://rest.ensembl.org/"
con <- "application/json"
ext_ping <- "/info/ping?"
x <- 0
while (x < 25) {
ping <- GET(paste(server, ext_ping, sep = ""), accept(con))
x = x + 1
print( paste ("count: ", x, "status:", status_code(ping), "remaining:", headers(ping)['X-RateLimit-Remaining']))
}