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:

  1. cache: The caching options, learn more about it here.
  2. storage: The storage options, learn more about it here.
  3. 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 to true or false to enable or disable it for everything. Can also fine tune it by providing a
    PreFetchConfig object.
  4. region: The region to use for the client (defaults to na).
  5. locale: The locale in which to fetch all the data (defaults to region's default). Since the default region is na, the default locale is en-US but it would also automatically update if you change the region.
  6. logger: The config options logging utility for debugging logs.
  7. ratelimiter: The options for the ratelimiter/requests queue. Check out the rate limiting docs to learn more about this.
  8. version: The version of the data dragon files to use. Defaults to the latest version.
The data dragon files are fetched automatically when making a request to one of the following APIs.
  • Spectator v4
  • Match v5
  • Champion Mastery v4
Therefore, it is recommended to prefetch them to avoid having to delay these requests.
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.