Skip to content

Initialization

Chau Nguyen edited this page Jul 18, 2017 · 20 revisions

There are two ways of initializing Kindred.

The fast way is through the QuickStart method.

The standard way is customizable, although it needs a bit of work still.

const KindredAPI = require('kindred-api')

const RIOT_API_KEY = 'whatever'
const REGIONS = KindredAPI.REGIONS
const LIMITS = KindredAPI.LIMITS
const InMemoryCache = KindredAPI.InMemoryCache
const RedisCache = KindredAPI.RedisCache

/*
  Default region for every method call is NA,
  but is settable during initialization or through
  `setRegion(region)`.

  To NOT use the built-in rate limiter, do NOT pass in anything
  into `limits`. Same if you don't want to use the cache (`cacheOptions`).
*/
const k = new KindredAPI.Kindred({
  key: RIOT_API_KEY,
  defaultRegion: REGIONS.NORTH_AMERICA,
  debug: true, // shows status code + url on request. enables showKey and showHeaders. 
  showKey: true, // puts api key in debug urls (for easy clicks :O)
  showHeaders: true, // shows headers
  limits: LIMITS.PROD, // LIMITS.DEV for DEV :p
  // [[500, 10], [30000, 600]]
  spread: true, // `false` for burst. Refer to `Rate Limiter` for more information.
  retryOptions: {
    auto: false,
    // numberOfRetriesBeforeBreak: 3 // for this to work, make sure you have auto: true, (ex: look at below)
  },
  // retryOptions: { // works
  //   auto: true
  //   numberOfRetriesBeforeBreak: 3
  // }
  timeout: 3000, // set request timeout in ms
  cache: new InMemoryCache(),
  // DEPRECATED // cacheOptions: CACHE_TYPES[0], // in memory,
  cacheTTL: {
    // refer to `Caching` section to see how to pass in your own timers
    // tl;dr. dont pass in cacheTTL and you get default cache timers I set up which are pretty good
  },
  // refer to https://github.com/ChauTNguyen/kindred-api/wiki/Rate-Limiter#method-rate-limiting for passing in customized method rate limits
})

showHeaders on: Imgur

showHeaders off: Imgur