Kotlin Ktor Improves Client-Server Support
Written by Mike James   
Monday, 04 November 2024

Kotlin Ktor 3 is now available with better performance and improvements including support for server-sent events and CSRF (Cross-Site Request Forgery) protection.

Ktor is a free open-source Kotlin framework for building asynchronous servers and clients in connected systems. It was created by the JetBrains Kotlin team using Kotlin and co-routines. This enables it to express complex asynchronous constructs as if they were simple sequential code. It also has the Kotlin advantages of being lightweight and flexible.

ktorbanner

The new release uses Kotlin 2.0 and switches to kotlinx-io, the official multiplatform asynchronous Kotlin library that provides basic IO primitives. The switch makes Ktor more up to date and better connected with other Kotlin tools. JetBrains says they made the change to standardize IO functionality across Kotlin libraries and improve performance, and that this has been shown in their benchmarks, where some tests based on real-world Ktor applications saw over 90% improvement. 

ktor performance benchmarks

Ktor 3 also has initial support for server-sent events (SSE) for both the server and the client. SSE lets servers push events to clients over an HTTP connection, providing a one-way communication channel from the server to the client. The Ktor team says this approach is useful when the server needs to send event-based updates without requiring the client to repeatedly poll for new information.

Support has also been added for CSRF (Cross-Site Request Forgery) protection. CSRF attacks trick end users into executing actions on web applications. Attackers typically use social engineering such as sending a link via email or chat to get the user t carry out actions such as transferring funds or changing their email address. The CSRF protection in Ktor is enabled for state-changing operations including POST, PUT, and DELETE. JetBrains says the protection is applicable only for projects that use session cookies and forms, since enabling this can unnecessarily complicate your application.

Other improvements include support for WebAssembly (Wasm) as a build target, even though Kotlin/Wasm is still at an early Alpha stage; there's also a new function, staticZip, that allows users to serve the contents of a ZIP archive as static content.

Ktor 3 is available now. 


ktorsq

  • Mike James is the author of Programmer’s Guide To Kotlin, 3rd Ed (I/O Press) written for Java programmers, Android developers and programmers wanting to discover why Kotlin is a better Java. This third edition was prompted by the release of Kotlin 2, which uses a new compiler that makes it faster. Kotlin 2 offers full support for Compose Multiplatform, a UI framework for cross-platform development that encompasses desktop, web, Android and iOS and a new chapter introduces the way Compose works and how it exploits Kotlin's unique features.

More Information

Ktor website

Related Articles

The Programmers Guide To Kotlin - The Class & The Object

Kotlin 2 Released With Multiplatform K2 Compiler

Kotlin Async Ktor 2.0 Released

How High Can Kotlin Go?

JetBrains Announces Kotlin Goodies

Kotlin 1.5 - Mature But Still Growing

<ASIN:1871962900>

<ASIN:B07S5CT71C>

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


Microsoft Introduces Vector Abstractions Library For .NET
21/11/2024

Microsoft has announced a preview release of the Microsoft Extensions VectorData Abstractions library, which can be used to help integrate vector stores into .NET applications and libraries.



CSS Ecosystem In the Spotlight
06/11/2024

The 2024 edition of the State of CSS has been posted, revealing that the latest features of the language not only do away with extra tooling, but even start taking on tasks that previously requir [ ... ]


More News

espbook

 

Comments




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