December 2017
Intermediate to advanced
260 pages
7h 34m
English
As we will always access the same API. We can set a base URL in the client. Also, for every request that is made, the Words API requires an API key in the header, for which we set the request interceptor to make sure every request sent using the client will contain the API key in the header.
We will perform this configuration in the init block. It can be added to the App class or the primary View as follows:
// Get the REST client private val api: Rest by inject() init { // Configuring the client api.baseURI = "https://wordsapiv1.p.mashape.com/words/" api.engine.requestInterceptor = { (it as HttpURLRequest).addHeader("X-Mashape-Key", Constants.WORDS_API_KEY) } }
Read now
Unlock full access