Search code examples
kotlinweb-applicationsktorspring-kotlin

Can we build a full stack webapp with kotlin?


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!


Solution

  • 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.