Ktor 3.4 Enhances Kotlin HTTP Client with New Features
JetBrains has released Ktor 3.4, the latest version of its popular Kotlin framework for building asynchronous server and client applications. This update introduces several new features aimed at improving how developers handle HTTP communications, especially with the OkHttp engine. The release was announced on January 23, and developers can find getting started guides at ktor.io.
Duplex Streaming Comes to OkHttp
One of the biggest updates in Ktor 3.4 is the addition of duplex streaming support for the OkHttp client engine. This feature allows clients to send request data and receive responses simultaneously. Unlike traditional HTTP calls, where the entire request must be sent before the response starts, duplex streaming enables real-time data exchange. This is especially useful for applications that require live updates or bidirectional communication over HTTP/2.
To enable duplex streaming, developers can set the new duplexStreamingEnabled property in the OkHttpConfig. This makes it easier to build applications that need continuous data flow, such as live chat apps, real-time dashboards, or streaming media services. Duplex streaming is only supported over HTTP/2 connections, ensuring high performance and efficiency.
Enhanced Request Management with New Plugins
Ktor 3.4 introduces a new HttpRequestLifecycle plugin. This tool helps manage ongoing HTTP requests, especially when clients disconnect unexpectedly. When a client disconnects, the plugin automatically cancels any in-flight requests related to that client. This prevents resources from being wasted on requests that are no longer needed and helps keep server performance optimal.
The plugin works by canceling the coroutine handling the request, along with any launch or async coroutines started by the client. It supports structured concurrency, ensuring all resources are cleaned up properly. Currently, this feature is supported only with the Netty and CIO engines, but it offers a valuable way to manage long-running or resource-intensive requests more effectively.
Additionally, Ktor 3.4 introduces a new API for dynamically generating API documentation at runtime. Instead of relying on static Swagger files, developers can embed documentation directly into their routing tree. This is made possible through a new compiler plugin and the describe API, which automatically generates documentation details as the application runs. Developers can enable this feature via the Ktor Gradle plugin, making it easier to keep API docs up-to-date and accurate.
Other Notable Improvements
The update also enhances the compression capabilities of Ktor. The Compression plugin now supports Zstd, a fast compression algorithm known for high compression ratios and low processing times. This support is provided through a new ktor-server-compression-zstd module, giving developers more options to optimize data transfer and improve application performance.
These improvements in Ktor 3.4 demonstrate JetBrains’ commitment to making Kotlin-based web development more efficient and flexible. By adding duplex streaming, better request lifecycle management, and improved documentation and compression tools, this release helps developers build faster, more responsive applications with ease.
Overall, Ktor 3.4 is a significant step forward for Kotlin developers looking to enhance their HTTP client and server applications. With these new features, creating real-time, resource-efficient, and well-documented services becomes much simpler and more effective.












What do you think?
It is nice to know your opinion. Leave a comment.