Paul Krill
Editor at Large

Kotlin-based Ktor 3.4 boosts HTTP client handling

news
Jan 26, 20262 mins

Update to the Kotlin-backed framework brings duplex streaming to the OkHttp client engine and the ability to cancel in-flight HTTP requests when the client disconnects.

Finger selecting the word "Kotlin" on a virtual screen.
Credit: GagoDesign / Shutterstock

JetBrains has released Ktor 3.4, an update to its Kotlin-based framework for asynchronous server-side and client-side application development. The release brings duplex streaming to the OkHttp client engine and introduces a new HttpRequestLifecycle plugin that enables the cancellation of in-flight HTTP requests when the client disconnects.

Ktor 3.4 was announced January 23. Instructions for getting started can be found at ktor.io.

The new HttpRequestLifecycle plugin, which enables cancellation of in-flight HTTP requests when the client disconnects, is useful when there is a need to cancel a long-running or resource-intensive in-flight request. When the client disconnects, the coroutine handling the request is canceled, along with launch or async coroutines started by the client, and structured concurrency cleans all resources. This feature is currently supported only for the Netty and CIO engines.

Ktor 3.4 also introduces a new API for dynamically documenting endpoints that works in tandem with a new compiler plugin. Instead of building a Swagger front end from a static file, the model is built at runtime from details embedded in the routing tree. To generate documentation, developers can enable it through the Ktor Gradle plugin, then it will automatically provide details in code via the new describe API.

Also in Ktor 3.4, the OkHttp client engine now supports duplex streaming, enabling clients to send request body data and receive response data simultaneously, in contrast to regular HTTP calls, where the request body must be fully sent before the response begins. Duplex streaming is available for HTTP/2 connections and can be enabled using the new duplexStreamingEnabled property in OkHttpConfig.

And the Compression plugin now supports Ztsd via a ktor-server-compression-zstd module. Zstd is a fast compression algorithm with high compression ratios, low compression times, and a configurable compression level.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author