Quarkus - Hello world example using Kotlin!

Quarkus - Hello world example using Kotlin!

Play this article

Quarkus with kotlin getting started example. If you are new to the quarkus then please watch the below video to get started with Quarkus.

[%youtu.be/B4h9dY3H678]

Tech Stack:

  1. Kotlin
  2. VSCode
  3. Quarkus
  4. GRadle
  5. REST API

Create Project:

Create a project using the launch Quarkus Initializr using https://code.quarkus.io/ or you can use the VSCode editor.

image.png

Check the above screenshot, we have specified the following details:

  1. Build Tool: Gradle with Kotlin
  2. Group: org.techwasti.demo
  3. Artifact: kotlin-quarkus-hello
  4. Search & Pick extensions: RESTEasy JSON-B

Generate a Quarkus project and downloads it. then, Unzip the downloaded zip file and import it into your favorite IDE.

image.png

See the Project Structure,

image.png

Quarkus core Technologies :

  1. Quarkus uses RESTEasy for the JAX-RS endpoint.
  2. Quarkus uses Vert.x and Netty at its core, providing a reactive and non-blocking HTTP layer.
  3. Quarkus uses JBoss Log Manager as the default logging framework.
  4. Quartus utilizes a modified version of Undertow that runs on top of Vert.x
  5. Quarkus uses SmallRye Config, implementation of Eclipse MicroProfile Config, for configuration data.

For testing:

  1. Quarkus uses JUnit 5 for testing.
  2. Quarkus uses rest-assured to test HTTP endpoints.

build.gradle file

plugins {
    id 'java'
    id 'io.quarkus'
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-resteasy-reactive-jsonb'
    implementation 'io.quarkus:quarkus-arc'
    implementation 'io.quarkus:quarkus-resteasy-reactive'
    testImplementation 'io.quarkus:quarkus-junit5'
    testImplementation 'io.rest-assured:rest-assured'
}

group 'org.techwasti.demo'
version '1.0.0-SNAPSHOT'

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

compileJava {
    options.encoding = 'UTF-8'
    options.compilerArgs << '-parameters'
}

compileTestJava {
    options.encoding = 'UTF-8'
}

Let us see the hello world controller coding.

package org.techwasti.demo;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from RESTEasy Reactive";
    }
}

In this code snippet, we have a GET endpoint that is returning the string. Let us run the command to build the project

gradle build

To run the application then use the below command.

./gradlew --console=plain quarkusDev

And hit URL

$ curl -w "\n" http://localhost:8080/hello

SourceCode:

Find the complete source code here.

https://github.com/knowledgefactory4u/Quarkus/tree/main/kotlin-quarku-helloworld

Conclusion:

This article demonstrates you quarkus kotlin helloworld application.

More such articles:

https://medium.com/techwasti

https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA

https://www.techwasti.com/

==========================**=========================

If this article adds any value for you then please clap and comment.

Let’s connect on Stackoverflow, LinkedIn, & Twitter.

Did you find this article valuable?

Support techwasti by becoming a sponsor. Any amount is appreciated!