Popular Kotlin Server-Side Libraries
Tags: kotlin, codenewbie, beginners, opensource
Published: 2020-11-22 02:11:08

[Kotlin](https://kotlinlang.org/) is a programming language for [mobile cross-platform] (https://kotlinlang.org/lp/mobile/), [native](https://kotlinlang.org/docs/reference/native-overview.html), [data science](https://kotlinlang.org/docs/reference/data-science-overview.html), [web](https://kotlinlang.org/docs/reference/js-overview.html), [Android](https://kotlinlang.org/docs/reference/android-overview.html), and [server-side](https://kotlinlang.org/lp/server-side/) development. 

# Kotlin for the Win

Kotlin is a great option for server-side development because it's a modern and concise take on JVM development.  If you write Kotlin code there are advantages to using libraries written in Kotlin versus libraries written in Java. Here are some of those advantages. 

There is less mental load when interacting with a Kotlin-specific library. That's because there is no context switching when you look at the source code of a library or are trying to debug a library feature. Additionally, Kotlin-specific library APIs are more idiomatic. In Kotlin functional programming is a first-class citizen. Many of these libraries lend themselves to functional programming over equivalent Java libraries meant for object oriented programming. Finally, you can avoid [Kotlin platform types](https://kotlinlang.org/docs/reference/java-interop.html). Kotlin platform types appear when you reference Java code from within Kotlin code. The type is not guaranteed as nullable or non-nullable, so you can still run into null pointer exceptions. With all that said, here is a list of popular libraries written in Kotlin.

## Web
[Ktor](https://github.com/ktorio/ktor) - A Kotlin web framework that has the most GitHub stars relative to other options. Can be used with a variety of the other options mentioned in this article.

[http4k](https://github.com/http4k/http4k) - A simple and functional HTTP client and server. 

[Kotless](https://github.com/jetbrains/kotless) - A Kotlin serverless framework.

## Testing
[Mockk](https://github.com/mockk/mockk) - A Kotlin [mocking](https://stackoverflow.com/questions/2665812/what-is-mocking) library. Mocking is commonly done when writing unit tests. Usually what isn't being tested is what you mock so that your individual test can focus on one function.

[Mockito Kotlin](https://github.com/nhaarman/mockito-kotlin) - If you're familiar with the Java Mockito library, then this one might be the right choice for you.

[Spek](https://www.spekframework.org/) - A good option if you're a fan of Jest. 

## Documentation
[Dokka](https://github.com/Kotlin/dokka) - The official documentation engine for Kotlin. It performs the same role as javadoc in Java.

## Dependency Injection
[Koin](https://github.com/InsertKoinIO/koin) - Has more GitHub stars of the two options. It has a simpler API.

[Kodein](https://github.com/Kodein-Framework/Kodein-DI) - A more robust API. Supports Kotlin multiplatform.

## Database
[Exposed](https://github.com/JetBrains/Exposed) - A Kotlin SQL ORM framework. It supports 7 different databases, including MySQL, PostgreSQL, and MariaDB.

[SQLDelight](https://github.com/cashapp/sqldelight) - Generates type-safe Kotlin models from your SQL statements. 

## Miscellaneous
[Okio](https://github.com/square/okio) - An I/O library. If you need to read or write data to a filesystem this is the library for you.

# Conclusion
There are a lot of different options for writing server-side Kotlin code. Additionally, many of these libraries are useful for more than just server-side development. Since Kotlin was first released, the ecosystem has matured and provides a lot of different options for Kotlin developers.

If you use Kotlin do make an effort to use libraries written in Kotlin? Or does it not matter to you? Let me know in the comments.