0Pricing
Kotlin Multiplatform Academy · Lesson

Add Ktor & Pick Platform Engines

Wire OkHttp and Darwin engines per target.

Add Ktor & Pick Platform Engines is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One HTTP Client Everywhere

Ktor Client is a multiplatform HTTP library, so you write networking once in commonMain and it runs on Android and iOS alike.

Core Plus Engine

Ktor splits into a shared core and per-platform engines. The core gives the API, the engine does the actual socket work.

Add the Core Dependency

In your shared module you add ktor-client-core to commonMain so every target can build requests with the same API.

implementation("io.ktor:ktor-client-core:2.3.12")

Android Wants OkHttp

For Android you pick the OkHttp engine, a battle-tested JVM client that Ktor wraps cleanly behind its shared API.

implementation("io.ktor:ktor-client-okhttp:2.3.12")

iOS Wants Darwin

For iOS you pick the Darwin engine, which runs on Apple's native URLSession under the hood for true platform networking.

implementation("io.ktor:ktor-client-darwin:2.3.12")

Engines Live in Source Sets

Each engine belongs in its own source set: OkHttp in androidMain and Darwin in iosMain, never in commonMain.

androidMain.dependencies { implementation(okhttp) }

Create the Client Once

In commonMain you create an HttpClient with no engine argument, and Ktor auto-selects the one bundled for that platform.

val client = HttpClient()

Auto Engine Selection

Because only one engine ships per target, Ktor's auto-selection finds it. Your shared code stays free of any platform import.

Or Pass an Engine

You can also pass an engine explicitly, which is handy when you want per-platform config like timeouts or proxies.

val client = HttpClient(OkHttp)

Close When Done

The client holds real resources, so call close when you no longer need it to release connections cleanly.

client.close()

Why Split This Way

This core-plus-engine design lets Ktor reuse each OS's best networking stack while you keep one shared API for all of them.

Quick Check

Which engine should an iOS target use?

Recap

Ktor shares a core API but needs an engine per platform: OkHttp for Android, Darwin for iOS. Auto-selection keeps shared code clean.

Frequently asked questions

Is the “Add Ktor & Pick Platform Engines” lesson free?

Yes — the full text of “Add Ktor & Pick Platform Engines” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Add Ktor & Pick Platform Engines”?

Wire OkHttp and Darwin engines per target. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Add Ktor & Pick Platform Engines” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Add Ktor & Pick Platform Engines
  2. Your First GET Request
  3. POST, Headers & Query Params
  4. Timeouts, Logging & Base URLs
← Back to Kotlin Multiplatform Academy