Skip to content

Instantly share code, notes, and snippets.

@hardik-trivedi
Last active December 5, 2020 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardik-trivedi/7f065de9059b5c59562fb3280c260085 to your computer and use it in GitHub Desktop.
Save hardik-trivedi/7f065de9059b5c59562fb3280c260085 to your computer and use it in GitHub Desktop.
Shared networking client class written using Kotlin which internally uses Ktor
class NovelCovidApiClient() {
companion object {
private const val URL = "https://corona.lmao.ninja/v2/countries"
}
private val httpApiClient: HttpClient = HttpClient {
install(JsonFeature) {
val json = kotlinx.serialization.json.Json { ignoreUnknownKeys = true }
serializer = KotlinxSerializer(json)
}
}
suspend fun getAffectedCountries(): List<CountryItem> {
return httpApiClient.get(URL)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment