Skip to content
🤔 Documentation issue? Report or edit

Installation

Setup

(You can also look how it’s done in the examples)

Gradle Plugins

You need to add KSP and the Ktorfit Gradle plugin

plugins {
  id("com.google.devtools.ksp") version "CURRENT_KSP_VERSION"
  id("de.jensklingenberg.ktorfit") version "1.14.0"
}

Next you have to add the Ktorfit KSP Plugin to the common target and every compilation target, where you want to use Ktorfit.

val ktorfitVersion = "1.14.0"

dependencies {
    add("kspCommonMainMetadata", "de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
    add("ksp[NAMEOFPLATFORM]","de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion")
        ...
}

[NAMEOFPLATFORM] is the name of the compilation target. When you want to use it for the Android module it’s kspAndroid, for Js it’s kspJs, etc. Look here for more information https://kotlinlang.org/docs/ksp-multiplatform.html

Ktorfit-lib

Add the Ktorfit-lib to your common module.

val ktorfitVersion = "1.14.0"

sourceSets {
    val commonMain by getting{
        dependencies{
            implementation("de.jensklingenberg.ktorfit:ktorfit-lib:$ktorfitVersion")
        }
    }

Ktor

Ktorfit is based on Ktor clients 2.3.10. You don’t need to add an extra dependency for the default clients. When you want to use Ktor plugins for things like serialization, you need to add the dependencies, and they need to be compatible with 2.3.10

You can also use “de.jensklingenberg.ktorfit:ktorfit-lib-light” this will only add the Ktor client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as “ktorfit-lib”


Last update: September 16, 2023