Nanoleaf Enters Beauty Tech with $150 LED Light Therapy Face Mask
Nanoleaf expands into beauty tech with an FDA Class II certified LED face mask, offering seven color modes for various skincare concerns.
Starfolk
Kotlin, a modern programming language built on top of the Java Virtual Machine (JVM), is gaining traction as a server-side language of choice for building web applications. In a recent example, Kotlin's server-side capabilities were showcased by adding persistent data and HTMX-powered views to a Ktor application, demonstrating the language's potential for building dynamic and performant web applications.
The example application, built on top of the Ktor framework, leveraged the Exposed ORM framework to interact with an SQL database. The Exposed framework provides a couple of ways to interact with the database, using either a DAO mapping or a DSL. Kotlin's native syntax makes the overall feel of using the ORM mapping layer less overhead-prone compared to other languages.
To add persistence to the application, the Exposed core and JDBC libraries, as well as a driver for the in-memory H2 database, were added to the build.gradle.kt file. The H2 database was used as a simple persistence mechanism that can easily be switched to an external SQL database like Postgres later on.
The application's QuoteSchema.kt file sets up the database schema and provides service functions for interacting with it. The file declares a Quotes object that extends Table, defining a table in the database with four variables: id, quote, author, and primary key. A data class called Quote is also declared, using the constructor style, with an optional id field. The QuoteService class is then created with two suspendable functions: create and list, which interact with the concurrent support in Kotlin using the IO dispatcher.
The Database.kt file pulls in the QuoteService and exposes endpoints for interacting with it. Two routes are created: a POST route for creating quotes and a GET route for listing them. The routes use the syntax developed in the first stage of the example and rely on the create and list functions and Quote class from QuoteSchema.
To create a UI to interact with the services using HTMX, a route is added that draws everything at the outset and then another route that accepts the form POST and returns the markup for the newly inserted quote. The quote is dynamically inserted into the list on the page, without a page reload. The HTMX library is included from a CDN, and several non-standard attributes (hx-post, hx-target, and hx-swap) are set on the form element.
The /quotes route accepts the incoming quotes from POST and responds with an HTML fragment that represents the new quote to be inserted into the list. The HTML fragment is generated using Kotlin's HTML DSL, which doesn't natively support sending HTML fragments. A workaround is used to wrap the quote markup in a body tag, which shouldn't be there.
In conclusion, Kotlin's server-side capabilities, combined with its powerful union of object-oriented and functional programming, and DSL capabilities, make it a compelling language for building web applications. The example demonstrates how Kotlin can be used to create a highly performant and dynamic stack without much overhead, making it an attractive choice for developers.
For those interested in exploring the complete source code for the Ktor-HTMX application example, it is available on GitHub.
Nanoleaf expands into beauty tech with an FDA Class II certified LED face mask, offering seven color modes for various skincare concerns.
The Global Firepower Index ranks the top 10 African countries with the strongest military power in 2025, with Egypt, Algeria, and Nigeria leading the list.
Get ready for Samsung's CES 2025 press event, focusing on AI-driven innovations, including smart refrigerators, and more.
Copyright © 2024 Starfolk. All rights reserved.