Quarkus - Demo Application

I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
Search for a command to run...

I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
No comments yet. Be the first to comment.
Quarkus is a Kubernetes Native Java stack tailored for OpenJDK HotSpot and GraalVM, crafted from the best of breed Java libraries and standards. We will learn about quarkus in this series
Quarkus IO is a microservices based java framework. According to QuarkusIO website , Quarkus is "A Kubernetes Native Java stack tailored for OpenJDK HotSpot & GraalVM, crafted from the best of breed Java libraries and standards". This course will tal...
Spring AI Tool Calling: From Chatbot to AI Agent with @Tool Your AI is smart. It knows an enormous amount. But it's frozen. It doesn't know what time it is right now. It doesn't know what's on your ca
Spring AI Advisors API Explained Series: Spring AI Complete Course — Lecture 4 of 12Reading Time: 8 minutesLevel: Intermediate Most developers stop at ChatClient. That is enough for demos. It is not
Working with Multiple AI Models in Spring AI Spring AI Complete Course — Lecture 3 of 12Previous: Lecture 2 — ChatClient API | Next: Lecture 4 — Advisors API In production AI applications, you rarel
Spring AI ChatClient API: The Fluent Heart of AI Integration Introduction If you've ever tried integrating AI models into a Java application, you know the pain. HTTP clients, API keys scattered everywhere, vendor-specific SDKs that never quite fit. W...
What is Spring AI? — Why Java Developers Need This in 2026 Every AI tutorial you see is in Python. LangChain, LlamaIndex, OpenAI SDK — all Python. But here's the uncomfortable truth: 80% of enterprise backends run Java. So who's building AI into thos...
Let's create an App which will recommend random quotes from a database. To start , let us generate an app using maven CLI .
mvn io.quarkus.platform:quarkus-maven-plugin:2.10.0.Final:create \
-DprojectGroupId=dev.pallav \
-DprojectArtifactId=quotes\
-Dextensions="resteasy-reactive"
cd quotes
To run the above project we can run the simple command and it will start the server at 8080 port.
./mvnw quarkus:dev
The above step has generated a GreetingResource as default which has an endpoint /hello
GreetingController has below code .
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello from RESTEasy Reactive";
}
}
We can use postman or curl to access the endpoint and validate if it works.
[codingsaint@fedora ~]$ curl http://localhost:8080/hello
Hello from RESTEasy Reactive
This showed how easy was it to create a working project with Quarkus.
Let us add more details. We will create QuotesResource will generate random quotes , to start with we will have 5 quotes and let it be picked randomly. We will evolve our system to learn event driven microservices. Our Quote object will be a simple record with author and quote
package dev.pallav.models;
public record Quote(String author, String quote) {
}
Let's create QuoteService
package dev.pallav.service;
import dev.pallav.models.Quote;
import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ApplicationScoped
public class QuoteService {
private List<Quote> quotes= new ArrayList<>();
public QuoteService(){
Quote q1= new Quote("Yoda", "Do, or do not. There is no try");
Quote q2= new Quote("Ralph Waldo Emerson", "Happiness is a perfume you cannot pour on others without getting a few drops on yourself");
Quote q3= new Quote("Oliver Holmes", "A man may fulfil the object of his existence by asking a question he cannot answer, and attempting a task he cannot achieve.");
Quote q4= new Quote("Napoleon Hill", "Opportunity often comes disguised in the form of misfortune, or temporary defeat");
Quote q5= new Quote("Mahatma Gandhi", "Our greatness lies not so much in being able to remake the world as being able to remake ourselves");
quotes.addAll(List.of(q1,q2,q3,q4,q5));
}
public Quote quote(){
Random random= new Random();
return quotes.get(random.nextInt(quotes.size()));
}
}
@ApplicationScoped - Let container know that bean is application scopedQuoteService constructor - initialize List of Quotes acting as temporary databasequote method pick a random quote
Since we want a RESTful endpoint with json output , let's add jackson support with dependency in pom.xml . <!-- Jackson -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
Not we can create the endpoint and invoke QuoteService to get a random quote.
package dev.pallav;
import dev.pallav.models.Quote;
import dev.pallav.service.QuoteService;
import javax.print.attribute.standard.Media;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("quote")
public class QuoteResource {
private final QuoteService quoteService;
public QuoteResource(QuoteService quoteService) {
this.quoteService = quoteService;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Quote quote(){
return quoteService.quote();
}
}
MediaType.APPLICATION_JSON with @Produces annotation to let endpoint produce a JSON response
Let's run the application and validate our service, We can curl to validate or use any client as postmancurl http://localhost:8080/quote
{"author":"Ralph Waldo Emerson","quote":"Happiness is a perfume you cannot pour on others without getting a few drops on yourself"}
In this article we created a Sample Quarkus Application and learn how to inject (Constructor Injection) a service . In next article we will add a database support and a POST endpoint to add quotes at database.