1. Home
  2. /
  3. Quarkus
  4. /
  5. Simple Counter API

Simple Counter API - Quarkus Typing CST Test

Loading…

Simple Counter API — Quarkus Code

Demonstrates a simple Quarkus REST API with a counter using JAX-RS annotations and in-memory state.

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
	}
}

Quarkus Language Guide

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.

Primary Use Cases

  • ▸Microservices development
  • ▸RESTful APIs with JAX-RS
  • ▸Serverless functions and cloud-native apps
  • ▸Reactive event-driven applications
  • ▸Integration with Kubernetes and OpenShift

Notable Features

  • ▸GraalVM native image support for ultra-fast startup
  • ▸Live coding with hot reload
  • ▸Reactive programming support
  • ▸Unified configuration system
  • ▸Extensive extension ecosystem

Origin & Creator

Quarkus was created by Red Hat in 2019 to modernize Java development for cloud-native environments.

Industrial Note

Quarkus is ideal for Java projects requiring high-performance, fast-startup, and cloud-native deployment with containerized environments.

More Quarkus Typing Exercises

Quarkus Hello World APIQuarkus Query Parameter ExampleQuarkus JSON Response ExampleQuarkus POST Form ExampleQuarkus Path Parameter ExampleQuarkus Error Handling ExampleQuarkus Redirect ExampleQuarkus Multiple Routes ExampleQuarkus Injected Bean Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher