## ✔ Key could be verified via a test request
## ℹ The provided key will be available for this R session
## ℹ Add `STATCUBE_KEY_EXT = XXXX` to "~/.Renviron" to set the key
## persistently. Replace `XXXX` with your key
Apart form /table
and /schema
,
there is also support for the simple endpoints /info
and /rate_limit
.
Server Information
The /info
endpoint gives and overview about the available languages on the
server.
sc_info()
# A data frame: 2 × 2
locale displayName
<chr> <chr>
1 de Deutsch
2 en English
Rate Limits (Table)
The /rate_limit
endpoint shows the number of calls to the /table
endpoint that are remaining.
#> 83 / 100 (Resets at [10:52:14])
In this case, we see that 8 out of the 100 requests per hour have
been used up and 92 are still available. The rate limit will be reset
once per hour. In this case this will be at
2022-08-30 13:53:55
. The entry under reset should always be
less than one hour after the request to the /rate_limit
endpoint was sent.
Rate Limits (Schema)
Schema requests are currently limited to 10000 requests per hour. The
number of remaining requests can be obtained via
sc_rate_limit_schema()
. Rate limits are be returned in the
same format as in sc_rate_limit_table()
.
#> 9996 / 10000 (Resets at [10:52:14])
Rate Limits from headers
All responses from the STATcube API contain rate limit information
(including remaining requests) in the response headers1. So instead of using
the /rate_limit*
endpoints shown above, it is also possible
to use responses from other endpoints and extract rate limit information
from their headers.
The function sc_rate_limits()
does just that. Any return
value from sc_table()
, sc_table_saved()
and
sc_table_custom()
can be passed to
sc_rate_limits()
and the rate limits will be extracted from
the response headers.
sc_example("population_timeseries.json") %>%
sc_table() %>%
sc_rate_limits()
#> $schema
#> 9996 / 10000 (Resets at [10:52:14])
#>
#>
#> $table
#> 82 / 100 (Resets at [10:52:14])
Note that the function gives rate limits for /schama
and
/table
even tough only the /table
endpoint was
used.
The function also works with return values from
sc_schema()
and friends.
sc_schema_catalogue() %>%
sc_rate_limits()
#> $schema
#> 9996 / 10000 (Resets at [10:52:14])
#>
#>
#> $table
#> 82 / 100 (Resets at [10:52:14])
Server-Side Caching
STATcube uses caching for the /table
endpoint by default. If the same request to sc_table()
is
sent several times, this will not count towards the rate-limit (100
requests per hour).
Server-Side caching of /table
responses is currently disabled due to security reasons. Therefore, all
requests against the /table
endpoint count towards the rate-limit.