Fetching data from the Dog API
To implement shared networking, we will be using Ktor (https://kotlinlang.org/docs/mobile/use-ktor-for-networking.html) and kotlinx.serialization (https://github.com/Kotlin/kotlinx.serialization).
First, let's add the dependencies:
- Add the following dependencies to the common source set:
io.ktor:ktor-client-core:$ktorVersion
io.ktor:ktor-client-json:$ktorVersion
io.ktor:ktor-client-logging:$ktorVersion
io.ktor:ktor-client-serialization:$ktorVersion
org.jetbrains.kotlinx:kotlinx-serialization-core:1.2.1
- We also need to apply the kotlinx-serialization plugin, by adding
kotlin("plugin.serialization") version kotlinVersion
to theplugins
block in the shared module'sbuild.gradle.kts
. - And we'll also need to add a dependency for the actual Ktor clients on the different platforms:
- Add
io.ktor:ktor-client-android:$ktorVersion
to the Android source set. - Add
io.ktor:ktor-client-ios:$ktorVersion
to the iOS source set.
- Add