Book Image

Hands-On Microservices with Kotlin

By : Juan Antonio Medina Iglesias
Book Image

Hands-On Microservices with Kotlin

By: Juan Antonio Medina Iglesias

Overview of this book

With Google's inclusion of first-class support for Kotlin in their Android ecosystem, Kotlin's future as a mainstream language is assured. Microservices help design scalable, easy-to-maintain web applications; Kotlin allows us to take advantage of modern idioms to simplify our development and create high-quality services. With 100% interoperability with the JVM, Kotlin makes working with existing Java code easier. Well-known Java systems such as Spring, Jackson, and Reactor have included Kotlin modules to exploit its language features. This book guides the reader in designing and implementing services, and producing production-ready, testable, lean code that's shorter and simpler than a traditional Java implementation. Reap the benefits of using the reactive paradigm and take advantage of non-blocking techniques to take your services to the next level in terms of industry standards. You will consume NoSQL databases reactively to allow you to create high-throughput microservices. Create cloud-native microservices that can run on a wide range of cloud providers, and monitor them. You will create Docker containers for your microservices and scale them. Finally, you will deploy your microservices in OpenShift Online.
Table of Contents (14 chapters)

Using Kotlin idioms

Kotlin provides a set of idioms that allows us to drastically reduce the amount of boilerplate code. Boilerplate refers to sections of code that have to be included in many places with little or no alteration. In this section, we will learn some of the most used idioms.

Inferred types

We may have a function written that returns a value, such as:

fun lower(name : String) : String {
val lower : String = name.toLowerCase()
return "$name in lower case is: $lower"
}

Here, we are explicitly indicating the type of the result of the function and the internal variable that we use inside.

In Kotlin, we could infer the type of the variable:

fun lower(name : String): String {
val lower = name.toLowerCase...