Kotlin Async Ktor 2.0 Released
Written by Mike James   
Tuesday, 03 May 2022

Ktor is a free open-source Kotlin framework for building asynchronous servers and clients in connected systems. As a major new version, Ktor 2.0 adds both new features and breaking changes.

ktorbanner

Created by the JetBrains Kotlin team, Ktor was built from the ground up using Kotlin and co-routines, which make it possible to express complex asynchronous constructs as if they were simple sequential code. It also has the Kotlin advantages of being lightweight and flexible.

One of the key improvements in Ktor 2.0 is simplified extensibility. Commenting on this in the release announcement on the JetBrains blog Hadi Hariri writes:

We’ve always built Ktor in mind for extensibility. Initially called Features, and now renamed to Plugins, all of the features (now you see why we renamed it) that Ktor offers are built using plugin architecture. The problem we encountered though was that for some folks it was hard to understand the architecture model behind it. In 2.0 we drastically simplified the extensibility API making the creation of plugins significantly easier. 

Another server side improvement is support for Kotlin/Native to complement existing support for GraalVM which was added in Ktor 1.6, giving devs two options for self-contained server applications.

On the client side, Ktor 2.0 introduces new APIs to deal with common HTTP requests.  Everything now returns an HttpResponse and is possible to access the response body simply with bodyAsText. Retries are now built-in to the client that allows for specifying the amount of time between retries. Ktor 2.0 also adds a content negotiation feature on the client side, while on the server side it was already implemented.

Referring to the breaking changes introduced by the new version,Hariri writes:

An issue we’ve had with Ktor has been the inconsistency of module and package names. Some had the prefix server, while others did not. Some worked for server and client, while not having any prefix whatsoever. In addition, we had multiple plugins in a single module, making discovery cumbersome. 

The change to a major version has provided us the opportunity to introduce some consistent naming conventions when it comes to modules and packages. Moving forward, anything that is only server, will have the server prefix. Anything that is client, will have the client prefix. Common packages will have the no prefix. In addition, plugins are now contained in their own modules. 

Ktor 2.0 is compatible with 1.6.20. To aid migration from earlier versions, Ktor 2.0 has a guide that provides instructions on how to migrate your Ktor application from the 1.6.x version to 2.0.0. There is also a migration tool with IntelliJ IDEA which attempts to migrate Ktor projects automatically.

ktorsq

 

More Information

Ktor 2.0 released (JetBrains blog)

Ktor website

Migrating from 1.6.x to 2.0.0

Related Articles

JetBrains Announces Kotlin Goodies

Kotlin 1.5 - Mature But Still Growing

Why Do Android Devs Convert To Kotlin?

Kotlin 1.3 Adds Duration And Time API

Kotlin Enters RedMonk's Top 20

Kotlin Gains A Foundation and A Portal

Can a Language Make You a Better Programmer? Kotlin & Android

Kotlin - New Language For Android

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Go Survey 2021
27/04/2022

Results of the 2021 Go Developer Survey, its sixth edition, show a very high level of satisfaction among users of the language and confidence in the long term direction of the Go project.



Feel Your Way Through VR Spider's Webs
02/05/2022

The mouth comes a close second to the fingertips in terms of tactile sensitivity. This led researchers from the Future Interfaces Group of the Human-Computer Interaction Institute at Carnegie Mellon U [ ... ]


More News

pythondata

 



 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962706>

<ASIN:1871962544>

 

Last Updated ( Tuesday, 03 May 2022 )