Client
Client constructor
const client = new Client('API_KEY');
Here, your API_KEY
is the key you want to use to make requests to the API.
This will create a new instance of the client, but it won't be ready for use yet. To make it usable, we move on towards the next section - Client initialization.
Client initialization
client.initialize({ // Client options});
Below are the details of the initialization options. Full details can be found in the ClientOptions interface.
Quick overview of the options:
cache
: The caching options, learn more about it here.storage
: The storage options, learn more about it here.fetch
: The pre-fetching options. You can use these two pre-fetch some data dragon data during initialization to avoid having to fetch it later, making the API requests MUCH faster. Disabled by default. Can be set totrue
orfalse
to enable or disable it for everything. Can also fine tune it by providing a
PreFetchConfig object.region
: The region to use for the client (defaults tona
).locale
: The locale in which to fetch all the data (defaults to region's default). Since the default region isna
, the default locale isen-US
but it would also automatically update if you change the region.logger
: The config options logging utility for debugging logs.ratelimiter
: The options for the ratelimiter/requests queue. Check out the rate limiting docs to learn more about this.version
: The version of the data dragon files to use. Defaults to the latest version.
- Spectator v4
- Match v5
- Champion Mastery v4
UPDATE in v1.4.0
Now only the data dragon files that are REQUIRED are fetched while making these requests, making the requests significantly faster.
Sample initialization config
const client = new Client('API_KEY');client.initialize({ cache: true, storage: false, region: 'na', logger: { enable: true, level: 'WARN' }, ratelimiter: { strategy: 'spread', throw: true, retry: { retries: 5, retryDelay: 5000 } }, fetch: { champions: false, items: true, runes: true, summonerSpells: true }});
With this config, our client will be initialized quickly, the default region will be set to na
,
the locale will be set to en-US
, which is the default locale for the region.
The data dragon files will be fetched from the API, but the champions will not be fetched.
The champions take the most time to fetch since there are so many of them and need to fetch 3 files for each of them. It is still recommended to keep this enabled in production, but in development this can slow down the initialization a lot. This is why all pre-fetching is disabled by default.
The fetched files will not be stored anywhere, but the processed JS objects will be cached in memory.
Updating locale and patch/version
League of Legends is a global, constantly-evolving game. There are players from a lot of different regions.
To allow fetching data in locales of all these various regions, the shieldbow client has the updateLocale
utility.
It can be used as follows
await client.updateLocale('ko_KR', false);
Here, the first argument is the new locale you want to use. ko_KR
is the default Korean locale.
The second argument (optional), is a refetch
option. This defaults to true
and will fetch all the data dragon data
right away using the new locale. This can take a while (almost the same amount as initialization)
if the data has not already been fetched and cached.
Similarly, every 2 weeks, the game is updated and all the values are updated. If you do not want to restart your app,
you can simply use the updatePatch
method which works in a similar way.
await client.updatePatch('11.10', false);
Here, the first argument is the new patch you want the information from.
It must be the patch number and not the data dragon version.
The second argument is the refetch
option that works in the same way as updateLocale
.
Next steps
From this point onwards, in the guide's code examples, we will be assuming, we have initialized the client already as in the example above.