gavel-gateway-js: Ratelimits and Caching

How Ratelimits Work

The Wynncraft API has a ratelimit. The default ratelimit without API keys is 180 requests every 60 seconds per IP. API keys can change that default limit. Every key has it's own request limit and reset interval. All ratelimits are IP contained.
gavel-gateway-js handles the ratelimit entirely as a background process. If more requests are called than can be handled by the API, further requests are delayed until the ratelimit clears up.

If multiple API keys are registered, the one with the most remaining requests is used. Although a specific API key can be used on calls by using the apiKey flag in RequestOptions.

Registering new Keys

To register apiKeys, you need to override the config. This will replace the apiKeys currently used with the ones passed in the options.

// Sets the config to use 2 API keys
// Key 1: 180 requests per 60 seconds
// Key 2: 10 requests per 10 seconds
api.setConfig({
apiKeys: [
{
key: "<API key here>",
limit: 180,
interval: 60000
},
{
key: "<second API key here>",
limit: 10,
interval: 10000
}
]
});

Checking the Ratelimits

If you feel like watching how requests affect your ratelimit, you can call the ratelimit() function. It will return a Ratelimit object. It contains information on the currently registered ratelimits, as well as currently ongoing requests

console.log(api.ratelimit());
The ratelimit function only exists to fuel your curiosity. You should not use it to try and delay requests. gavel-gateway-js already does that for you.

Caching

gavel-gateway-js caches requests for as long as specified in the config. If the allowCache option is set, new requests will draw from cache. This preserves time and doesn't count towards the ratelimit.

If you request raw data using the fetchRaw() function with reuseJson enabled - which it is by default, you should not modify the data in downstream code. Doing so will modify the cache entry and may cause errors if the route is requested by other parts of the code

Generated using TypeDoc