[Android] Talking Retrofit Localization, Part 1

Profile Picture
- Published on Feb 21, 2020馃審 Public

Digging into Accept-Langauge header. Plan to explore LocaleListCompat.getDefault().toLanguageTags()

For today's stream though, we will simply set up a basic Android app that can hit an API.

We will use Retrofit and connect to the Github API. We will use Kotlin Coroutines to make the API call.

We will explore the new Kotlin Serialization library as well as the Kotlin Serialization Converter.

Heads up, we found out that if you don't serialize all elements, you'll want to use the nonstrict mode of the serialization library. Surprised this isn't the default:

        val contentType = MediaType.get("application/json")
        val retrofit = Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(
                Json(configuration = JsonConfiguration.Stable.copy(strictMode = false)).asConverterFactory(
                    contentType
                )
            )
            .build()

        val service = retrofit.create(GitHubService::class.java)