How to Create Microservices Using http4k

How to Create Microservices Using http4k

A developer gives a tutorial on how to create a simple microservice-based application using http4k, Kotlin, and JDBI.

In this article, we will build a simple microservice based on Kotlin, the http4k toolkit , and JDBI.

Our Use Case

Let's consider a simple functionality: registering companies and generating a ranking system. Each company has a score based on their foundation date. Companies are classified by their score, so we have a simple solution, as described below:

article image    

The above diagram shows a simple service with it own database. We are assuming that the Ranking Web (UI) Application will interact with Company Service to show the company list. Let's take a look at some design points:

  • Language/Toolkit: We are using the http4k toolkit. This toolkit provides a simple and uniform way to serve, consume, and test HTTP services. It was entirely written in Kotlin and brings with it the concept of "function as service." http4k provides many server runtimes, such as Netty, Apache, Ktor, etc.
  • Persistence: all data will be managed via JDBI. JBDI is a library that provides an idiomatic access to relational data in the Java world. All data will be stored in a PostgreSQL database.
  • Testing: All services need to be tested and require a lot of testing. To create our unit tests, we are using Kotest and JUnit. Kotest has an amazing DSL for testing, making our tests more fluent.

Getting Started

We will start from the repository, ranking-service. All boilerplate code is provided in this initial repository. Let's build the registration operation. First, when we create a company record, we need to set the company's score in our ranking system. The score calculation is based on its foundation date, so we have some rules for that:

  • Companies less than 2-years-old cannot be included in our rankings.
  • Companies between 2- and 3-years-old have a score of "C".
  • Companies between 4- and 5-years-old have a score of "B".
  • Companies that are 6-years-old or more have a score of "A".

kotlin

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Kotlin App Development Company in India, Hire Kotlin Developers

Looking for Kotlin app developers in India? We are the best kotlin app development company in India offering top notch kotlin based application development services.

Hire Dedicated Kotlin Developer - WebClues Infotech

Request a free quote for custom web and mobile apps development, Enterprise solutions, IoT Solutions, AR/VR Development, Blockchain and chatbot services. Feel free to get in touch.

How to Develop an Android App with Kotlin?

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Top Kotlin Android App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Top-notch Kotlin App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!