AI Creator's Path News: Ktor 3.2.0 released! Accelerate asynchronous app development with DI and HTMX support! #Ktor #Kotlin #AsynchronousApp
Video explanation
Ktor is now even more convenient! What are the new features "DI" and "HTMX"? A simple explanation for beginners!
Hello, I'm John, who brings you the world of AI and technology in an easy-to-understand way! Today, I'd like to talk about a topic that's been a hot topic among programmers:KtorI have some very exciting news to share with you about a tool called Ktor. Have you heard of Ktor? It's a kind of magic toolbox that helps you write smart programs, especially "asynchronous applications," which are programs that can do a lot of things at once.
Ktor is developed by JetBrains, the company that creates the modern programming language Kotlin. Recently, Ktor has beenVersion 3.2.0" and it has been revamped and is now even more powerful!
Don't worry if you're thinking, "Even if it's called a new feature, it sounds difficult..." In this article, John will explain the notable new features of Ktor 3.2.0 in detail and in an easy-to-understand way so that even those who are not familiar with AI or programming will think, "Oh, I see!"
First of all, what is Ktor?
Ktor is a framework for creating web services and apps (server side) and apps that run on various devices (client side). A framework is like a framework or blueprint when building a house, and having one makes development much easier.
Ktor is good at:Asynchronous processing" This is like the way a waiter works at a good restaurant. A waiter can take orders from table A, bring water to table B, and handle the bill for table C... Imagine being able to efficiently carry out multiple tasks simultaneously. Using Ktor makes it easy to create such smart applications.
Point of interest 1: Development becomes easier! Introducing the "DI (Dependency Injection)" module
Now, one of the highlight features of Ktor 3.2.0 is "DI (Discrete Eye) Module" has been added. You may be wondering, "What is DI?" This is an abbreviation for "Dependency Injection," which is translated into Japanese as "Dependency Injection."
It may seem difficult to understand, but in simple terms,A system that allows necessary program components to be delivered from outside" That's what I mean.
- For example, if you want to make curry, without DI, you would have to go to the supermarket and buy potatoes, carrots, meat, etc. by yourself.
- But with DI, it's like someone has prepared the perfect ingredients and handed them to you, saying, "Here are the ingredients that are perfect for today's curry!" You can concentrate on cooking (programming)!
With the addition of this DI module to Ktor, Ktor itself will take on part of the role of "passing materials," allowing developers to focus more on creating the main body of the program. Moreover, Ktor's DI is based on "coroutines" (another Kotlin feature for handling asynchronous processing), so applications start up smoothly. It is also designed to be easily integrated with existing DI mechanisms. In addition, it has a function that automatically cleans up parts that have been used, which is very convenient!
Highlight 2: Make your web pages richer! "HTMX" module makes development easier
Another major point of interest is,HTMX (High Temperature Multiplier) Module” is added.
You might think, "HTML is another new word...", but it's a new technology that makes web pages "easier to use and more interactive (more dynamic)".
Normally, to add movement to a web page or to update only a part of the page with new information, you need to write a lot of code in a programming language called "JavaScript." However, with HTML, you can achieve such movement by simply writing a few instructions in the language that creates the framework of a web page, called "HTML." In other words,It becomes easier to provide rich web experiences without having to write lots of JavaScript
Ktor's new HTMX module is deeply integrated with "kotlinx.html" (a library that makes it safe and easy to write HTML using Kotlin) and Ktor's routing function (a mechanism that links website URLs and program processing). This allows developers to easily write special HTML instructions (attributes) required for HTMX and automatically include information (headers) required for HTMX communication. It looks like web development will become more intuitive and faster!
Handle configuration files smartly! Supports "typed configuration"
Ktor 3.2.0 has also improved the way it handles program configuration files. When creating a program, various configuration information (such as database connection destinations and authentication keys for external services) is required. These are usually stored in a separate file called a "configuration file."
In the new Ktor, change the contents of these configuration files to "Data ClassThe function that automatically converts and loads data into a "typed box" that is convenient for handling data in bulk in Kotlin has been enhanced (the technical term for this is "deserialization").
First, the developer defines a data class (like a blueprint) that represents the information they want, and then prepares a corresponding YAML format file (a format that allows configuration files to be written in a way that is easy for humans to read). Ktor then automatically pours the contents of the configuration file into the data class. This makes it possible to handle configuration information more safely (less likely to cause mistakes) within a program, which also helps prevent bugs.
There are lots of other exciting updates!
Ktor 3.2.0 also includes a number of other exciting improvements for developers.
- Asynchronous module support (suspended modules): Even if there is a process that takes time to initialize (for example, connecting to an external service), you can now proceed with other preparations while waiting for that to happen, or perform complex preparation tasks in parallel. This allows you to write more efficient programs!
- Gradle version catalog support: We have added support for the "Gradle Version Catalog" mechanism, which allows you to manage version information for many components (libraries) used in a project in one place. This makes version management simpler.
- Unix domain socket support: Ktor's CIO engine (one of the core components responsible for data exchange) now supports "Unix Domain Sockets", a faster and more efficient way for programs running on the same computer to exchange information.
- Android R8 Notes: It seems that some issues (regressions, bugs that did not exist before) have been confirmed in Ktor 8 related to the tool "R3.2.0" used in Android app development. However, this is scheduled to be fixed in the next version, Ktor 3.2.1, so Android developers may be relieved if they wait a little longer.
What can you make with Ktor?
According to JetBrains, Ktor aims to make it easier to develop "asynchronous client and server applications." Specifically, it can be used for a wide range of applications, from the systems that run behind websites (suitable for creating collections of small services called microservices) to applications that run on smartphones and PCs and communicate with the Internet (multiplatform HTTP client apps).
A word from John
Wow, Ktor's evolution never stops! In particular, the support for DI (dependency injection) and HTMX this time is a welcome enhancement for developers who have been waiting for it. It's exciting to think that as these useful tools continue to evolve, we users will be able to experience more comfortable and innovative services. The progress of technology is really interesting!
This article is based on the following original articles and is summarized from the author's perspective:
Ktor adds dependency injection and HTMX modules