QuickStart with Quarkus!

quarkus
Reading Time: 3 minutes

Quarkus is in trend for being the framework that is optimized for run-time Java environment with container first Approach. In this blog, we will briefly introduce Quarkus and will focus on how quickly we can kickstart with the “Hello World!” of Quarkus.

What is Quarkus?

Java has evolved a long way ever since it was born. At the time of inception, there was no cloud. With the advancement of cloud technology, microservices architectures, and containerization technology, eagerness to scale microservices as fast as possible and get them running in as many instances/pods/containers whatever you say has been a challenge. Quarks solve it by reducing the runtime space and ahead-of-time compilation. If you are intrigued now! Check the details here.

Where to Get Started?

Quarkus have very rich documentation and there are tons of example and template from which we can start a new project. That is why I planned to write this blog as I myself lost many times inside the Matrix of examples!! In my example, I was very eager to start a REST API in Quarkus just like we have other initializers. Quarkus gives a single command which you can use with Quarkus CLI to generate an example project.

Prerequisites

  • JDK 11+ installed with JAVA_HOME configured appropriately in the PATH.
  • Apache Maven 3.8.1+

Before proceeding with the rest of the instructions, make sure that the Quarkus CLI is installed on your system.

Once you are done with installing the Quark CLI. Run the command as instructed and you will get your project generated promptly. Here is a reference to the output of the generated project.

What Did we generate?

If you pay attention to the command above, The switch –extension=reasteasy-reactive will initiate a new JSON REST service named quarkus-rest-example. Let us expand the project in IDEA and check what are the different components generated from this project.

As you can refer to the above image, the template generates a class called GreetingResource which has a GET endpoint defined as a “/hello”. Similarly, there are two types of Test cases that are also generated that are GenerateResource unit test and GenerateResourceIT i.e. probably the integration test file.

Running the example

You would find a very good README generated to walk you through different ways of running the example. I would not quote the same here as the template may change the instructions with a different version. Let me share you glimpse of the README here and advise you to look into the actual README generated to run the example. Once you follow the instructions in the README, you would see the application running at port 8080.

Quarkus Started!

The generated template comes with a dev UI which is also served at the same endpoint. If would simply open http://localhost:8080/ in the browser, you would get something like the below which prints all the details of your generated application.

Quarkus Dev UI

Remember we created a hello endpoint. If you call that, it would behave the same as a REST service with GET endpoint.

So far, we have only gone through how to bootstrap a Quarkus project and run it. There is so much more that I wanted to cover like we talked about containerization and native application generation by Quarkus. Keeping the length of this blog short, we will cover the same and would focus on understanding the structure of the project and different under-the-hood things which make Quarkus run. Thanks for Reading!! Stay Tuned!

References

Written by 

Manish Mishra is Lead Software Consultant, with experience of more than 7 years. His primary development technology was Java. He fell for Scala language and found it innovative and interesting language and fun to code with. He has also co-authored a journal paper titled: Economy Driven Real Time Deadline Based Scheduling. His interests include: learning cloud computing products and technologies, algorithm designing. He finds Books and literature as favorite companions in solitude. He likes stories, Spiritual Fictions and Time Traveling fictions as his favorites.

Leave a Reply