1

Kotlin official documentation tells that it supports web development. And its replacement for java. I am trying to build a web application using Kotlin. So far I read so many blogs, courses and videos in YouTube but I did not succeed coming up with a flow. I came across this link https://medium.com/bcgdv-engineering/building-a-full-stack-web-app-in-kotlin-af8e8fe1f5dc and I could not proceed with this alone. I only need a front end and connect to my server with normal http request. Is there any right way of doing a web app in kotlin. Please help me with this. Thanks in advance!

Sundar Nivash
  • 306
  • 6
  • 25
  • Your question feels very incomplete. You mention you've find a walktrhough article but "could not proceed with this alone" - do you mind clarifying what specific problems you've encountered? It's unclear to me what kind of answer you're looking for. – Egor Apr 03 '20 at 12:49
  • In that link he is doing front end and back end. I need to know can we have html css and can we have beautiful UI, call API like that? there are so many options like ktor, spring.io spark and so on. Cant I do the traditional html css? I dont know to proceed. I worked in android kotlin, we just need android studio and write our code. Like that is it possible for web with kotlin? @Egor – Sundar Nivash Apr 03 '20 at 12:59

1 Answers1

4

What I use for developing web apps in Ktor:

Front-End:

  • FreeMaker - for templating (mustache and velocity are other options)
  • Bootstrap - for HTML - CSS - Javascript part

There is also Kotlinx.html and KotlinJS if you need to write them Kotlin Style and they are official toolset from JetBrains.

Kotlinx.HTML Github

KotlinJS

You can add functionality to Ktor itself (they are called features):

Features:

  • GSON - for content negotiation (converting Kotlin to JSON and visa versa)
  • Locations - for type-safe routing
  • Exposed (Interface for easily working with PostgreSQL, MySQL and SQLite that works based on JDBC drivers)
  • Authentication (for user auth)

Ktor website has detail documentation for all of these features and adding them in your project is so easy.

  • Add the dependency

  • install(FEATURE) in Application.

For the IDE side:

  • IntelliJ Ultimate (Ultimate supports .ftl for FreeMarker)
  • Ktor plugin which is a must-have when you install IntelliJ

For webserver engine:

  • Netty (I use this one)
  • Tomcat
  • Jetty

You can easily develop API and Wen Apps using Ktor amazing DSL (Domain Specific Language)

The only problem that I have is with Kotlin Coroutines which I hate, and prefer RxKotlin for developing asynchronous apps, it seems that's possible but there are not enough tutorials and samples out there to get started with it. + If you stuck on something new and challenging, you are on your own, as there are not enough samples and guides on the internet.

But at the end of the day, I only recommend Ktor to those android developers who don't want to learn web development language e.g. PHP, Phyton, Javascript, like myself.

Arrowsome
  • 2,649
  • 3
  • 10
  • 35
  • PHP I did for 10 years but its fading, was never intended for programming anyway. Python with Flask looks pretty good. ktor as a server I enjoy, mostly because it behaves like java without making me use it (least favorite language, it's like C++ but requires a VM). In using ktor though, I am strapped for a good frond end solution that fits in with this. What do you do with your JS files, just put them in the resources folder? It has HTML & CSS but no inherent JS DSL, while I heard kotlinJS isn't really being developed. – gunslingor Aug 09 '20 at 17:26