Learn Quarkus - 10 Code Examples & CST Typing Practice Test
Quarkus is a Kubernetes-native Java framework designed for building cloud-native, high-performance applications. It emphasizes fast startup times, low memory usage, and developer productivity.
View all 10 Quarkus code examples →
Learn QUARKUS with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Quarkus Simple Counter API
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/counter")
public class CounterResource {
private int count = 0
@GET
@Produces(MediaType.APPLICATION_JSON)
public int getCount() {
return count
}
@POST
@Path("/increment")
@Produces(MediaType.APPLICATION_JSON)
public int increment() {
return ++count
}
@POST
@Path("/decrement")
@Produces(MediaType.APPLICATION_JSON)
public int decrement() {
return --count
}
@POST
@Path("/reset")
@Produces(MediaType.APPLICATION_JSON)
public int reset() {
count = 0
return count
}
}
Demonstrates a simple Quarkus REST API with a counter using JAX-RS annotations and in-memory state.
Quarkus Hello World API
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello, Quarkus!"
}
}
A minimal Quarkus REST API returning Hello World.
Quarkus Query Parameter Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/greet")
public class GreetResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String greet(@QueryParam("name") String name) {
return "Hello, " + (name != null ? name : "Guest")
}
}
Demonstrates query parameters in Quarkus REST API.
Quarkus JSON Response Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
import java.util.Map
@ApplicationScoped
@Path("/json")
public class JsonResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Map<String, String> json() {
return Map.of("message", "Hello, Quarkus JSON")
}
}
Return JSON response from Quarkus REST API.
Quarkus POST Form Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/form")
public class FormResource {
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String handleForm(@FormParam("name") String name) {
return "Hello, " + name
}
}
Handle POST requests with form parameters.
Quarkus Path Parameter Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/user")
public class UserResource {
@GET
@Path("/{id}")
@Produces(MediaType.TEXT_PLAIN)
public String getUser(@PathParam("id") String id) {
return "User ID: " + id
}
}
Use path parameters in Quarkus REST API.
Quarkus Error Handling Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/error")
public class ErrorResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String error() {
throw new WebApplicationException("This is an error", 400)
}
}
Demonstrates basic exception handling in Quarkus.
Quarkus Redirect Example
import javax.ws.rs.*
import javax.ws.rs.core.Response
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("/redirect")
public class RedirectResource {
@GET
public Response redirect() {
return Response.seeOther(URI.create("/counter")).build()
}
}
Redirect request to another endpoint.
Quarkus Multiple Routes Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
@Path("")
public class MultiResource {
@GET
@Path("/")
@Produces(MediaType.TEXT_PLAIN)
public String home() {
return "Home"
}
@GET
@Path("/about")
@Produces(MediaType.TEXT_PLAIN)
public String about() {
return "About"
}
}
Handle multiple routes in one Quarkus application.
Quarkus Injected Bean Example
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
@ApplicationScoped
@Path("/bean")
public class BeanResource {
@Inject
CounterService service
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
return "Count: " + service.getCount()
}
}
@ApplicationScoped
class CounterService {
private int count = 0
public int getCount() { return count }
public int increment() { return ++count }
}
Use CDI to inject a bean into a Quarkus REST API.
Frequently Asked Questions about Quarkus
What is Quarkus?
Quarkus is a Kubernetes-native Java framework designed for building cloud-native, high-performance applications. It emphasizes fast startup times, low memory usage, and developer productivity.
What are the primary use cases for Quarkus?
Microservices development. RESTful APIs with JAX-RS. Serverless functions and cloud-native apps. Reactive event-driven applications. Integration with Kubernetes and OpenShift
What are the strengths of Quarkus?
Extremely fast startup and low memory footprint. Developer-friendly live reload. Supports both reactive and imperative programming. Rich extension ecosystem for integrations. Optimized for containerized/cloud-native deployments
What are the limitations of Quarkus?
Java-specific - not suitable for other languages. Steeper learning curve for reactive programming. Requires understanding GraalVM for native images. Less mature compared to Spring ecosystem for some features. Initial configuration can be complex for beginners
How can I practice Quarkus typing speed?
CodeSpeedTest offers 10+ real Quarkus code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.