Kotlin / Ktor / Jdbi Json / Api / Free Marker / VueJs
About this blog
A brief reason for writing this blog. I am a server side http api / web developer predominantly using JVM based languages. Recently I started using Kotlin programming language (developed by JetBrains) with Spring Boot Framework on AWS cloud to build an enterprise solution (including both API and small web portal for internal Admins) to serve data for the mobile apps. I loved Kotlin as a programming language for Server Side development. So I was curious to explore Ktor Framework (developed and sponsored by JetBrains) for Server Side Web Development (API & Webpages). Hence I created a sample repository in Git Hub to play with Ktor Framework to experiment with various enterprise grade features offered by Ktor Framework. Please read this blog in conjuction with my Kotlin repository available at
https://github.com/harishkannarao/kotlin
High Level Components Diagram
API
The API development was very very simple with Jackson / Google GSON integration. The Ktor documentation covers extensively about the API development with Ktor
Integration or Functional Testing
The following test shows an example of integration or functional testing of an api. It performs basic CRUD and Search operation of an entity in Postgres database through Jdbi library via http api. The test also demonstrates the ability to start the Ktor application and execute the http requests to the running server and shutdown the application after test completion. This allows us to test every feature developed using the Ktor framework using a black box style integration tests.
https://github.com/harishkannarao/kotlin/blob/master/ktor-integration-test/src/test/kotlin/com/harishkannarao/ktor/api/JdbiJsonEntityIntegrationTest.kt
Feature Toggled Testing
Feature toggles enables continuous delivery of an application to live environment without breaking existing functionality for live users with new developmental or experimental featues. Hence it is very important to test the new feature and old features with feature toggles using black box integration tests. The following test restarts Ktor application during feature toggle through configuration, which allows to integration test the features with toggle on and off.
https://github.com/harishkannarao/kotlin/blob/master/ktor-integration-test/src/test/kotlin/com/harishkannarao/ktor/api/HttpsRedirectIntegrationTest.kt
Free Marker, Vue Js and Webjars
Ktor seamelessly integrates with Free Market templating library, which allows to render dynamic html pages from server and also allows to configure or supplement client side interactivity using Vue Js. Ktor also supports Webjars integration, which enables pulling java script dependencies as jar dependencies using Gradle without the need of using Node JS and NPM
The following test performs Free Marker page with Vue Js application to exercise Create and Delete operations of an entity using an api
https://github.com/harishkannarao/kotlin/blob/master/ktor-integration-test/src/test/kotlin/com/harishkannarao/ktor/web/vue/VueCrudIntegrationTest.kt
Minification of JavaScript and CSS files
It is essential to minify JavaScript and CSS files to speed up the page load in production environment. Hence the following gradle task helps to scan and minify all JavaScript and CSS files before generating deployable artifact using Gradle tool
./gradlew clean minifyFiles
Comments
Post a Comment