May 11, 2024

Tinkering With Ktor 3: Practical uses of Ktor's plugin system

Summary Ktor isn’t just a small and snappy framework, it features a simple, yet effective plugin system to extend the framework to your heart’s content. My team uses this feature extensively, and I’ve used it in several of my side projects. Let’s play with a few example and see what we can do. Simple example Let’s say, we want to see how long does it take for server to process a request until it responds. We can create a new plugin in plugins/MeasureTimeToResponse.kt with the following code: Read more

March 30, 2024

Tinkering With Ktor 2: Using HTML DSL for page templates

Photo by Pankaj Patel on Unsplash Summary There are a bunch of templating engines available for Ktor, each one with its own strengths and weaknesses. But, I don’t like that I have to add yet another engine to the runtime (especially when I plan to run React or Vue anyway) so why not try using a simple feature of Kotlin to build our html? Kotlin DSL (Domain Specific Language) capabilities, while having a steep learning curve if you never used them before can be used structures that closely mimic html. This is not a new idea, there have been several attempts at this and the most popular one is the kotlinx.html library. Ktor team already created a convenient way to plug this library into your Ktor project, called ktor-server-html-builder. The kotlinx.html library gives us the basic components of HTML and we can extend that further if we want. Let’s see what can be accomplished with these. Read more

January 7, 2024

Tinkering With Ktor: Setting up a simple server with Docker

Summary After doing a few small projects on Android, I’ve come to enjoy Kotlin’s convenient syntax that strikes a beautiful balance between functional and imperative programming. After doing some research, it looks like Kotlin has been gaining popularity on the server-side as well and for good reasons, it’s so darn productive. I’ll be doing a small series of posts on how to use Ktor framework, for my own learning and hopefully for yours as well :) Read more

© Ilya Nemtsev 2025

Powered by Hugo.