Ktor Client — HTTP Client for Kotlin

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

What is Ktor Client?

Ktor Client is an asynchronous HTTP client for the Kotlin programming language, developed by JetBrains. It is part of the Ktor framework, which is designed for creating server and client applications. Ktor Client allows you to send HTTP requests (GET, POST, PUT, DELETE, and others) and process responses, supporting work with various engines (OkHttp, Apache, CIO, Android, etc.).

Why do you need Ktor Client?

Ktor Client is used for interacting with REST APIs, downloading data from the internet, submitting forms, working with WebSocket, and integrating with cloud services. It is entirely written in Kotlin, which ensures type safety and concise code. Thanks to support for coroutines and Flow, Ktor Client is ideal for asynchronous and reactive applications.

How to install Ktor Client?

To use Ktor Client in a Kotlin project, add the dependencies to the build.gradle.kts file:

dependencies {    implementation("io.ktor:ktor-client-core:2.3.12")    implementation("io.ktor:ktor-client-cio:2.3.12") // CIO engine    implementation("io.ktor:ktor-client-content-negotiation:2.3.12") // for JSON    implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.12") // serialization}

If you use Maven, add the corresponding dependencies to pom.xml.

Main features

  • Multiple engines: OkHttp, Apache, CIO, Android, iOS (Darwin), JavaScript.
  • Asynchrony: Full support for Kotlin coroutines (suspend functions).
  • Plugins: Content Negotiation (JSON/XML), Logging, Auth (Basic, Bearer, OAuth), Cookies, WebSocket.
  • Type safety: Serialization and deserialization via kotlinx.serialization.
  • Streaming: Working with large files via streaming.

Kotlin code example

import io.ktor.client.*import io.ktor.client.engine.cio.*import io.ktor.client.request.*import io.ktor.client.statement.*import io.ktor.http.*import kotlinx.serialization.Serializableimport io.ktor.client.plugins.contentnegotiation.*import io.ktor.serialization.kotlinx.json.*

@Serializabledata class Post(val userId: Int, val id: Int, val title: String, val body: String)

suspend fun fetchPost(): Post { val client = HttpClient(CIO) { install(ContentNegotiation) { json() } } val response: HttpResponse = client.get("https://jsonplaceholder.typicode.com/posts/1") val post: Post = response.body() client.close() return post}

fun main() = runBlocking { val post = fetchPost() println("Title: ${post.title}")}

When to use Ktor Client?

Ktor Client is recommended for use in Kotlin projects (JVM, Android, Native, JS) where a lightweight, asynchronous, and modern HTTP client is required. It is especially useful in microservices, Android applications, multiplatform projects (KMP), and when working with Kotlin Coroutines. If you need full integration with the Kotlin and JetBrains ecosystem, Ktor Client is the best choice.

Recommendations