Building a Retrofit service instance

Now, after we have described our service, we need a real Retrofit instance that we will use to trigger API calls. First, we will introduce some additional classes. We will hold the latest token instance inside the TokenManager object:

    package com.journaler.api 
     object TokenManager { 
       var currentToken = JournalerApiToken("", -1) 

We will also have an object to obtain the API call headers map called BackendServiceHeaderMap, as shown here:

 package com.journaler.api object BackendServiceHeaderMap { fun obtain(authorization: Boolean = false): Map<String, String> { val map = mutableMapOf( Pair("Accept", "*/*"), Pair("Content-Type", "application/json; charset=UTF-8") ) if (authorization) { map["Authorization"] ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.