1. Home
  2. /
  3. Micronaut
  4. /
  5. Combined Routes Example

Combined Routes Example - Micronaut Typing CST Test

Loading…

Combined Routes Example — Micronaut Code

Multiple endpoints: counter, echo, and greeting combined.

import io.micronaut.http.annotation.*;
import javax.inject.Singleton;
import java.util.Map;

@Singleton
class CounterService {
	private int count = 0;
	public int getCount() { return count; }
	public int increment() { return ++count; }
	public int decrement() { return --count; }
	public int reset() { count = 0; return count; }
}

@Controller
class CombinedController {
	private final CounterService service;
	CombinedController(CounterService service) { this.service = service; }

	@Get("/counter") public int getCount() { return service.getCount(); }
	@Post("/counter/increment") public int increment() { return service.increment(); }
	@Post("/counter/decrement") public int decrement() { return service.decrement(); }
	@Post("/counter/reset") public int reset() { return service.reset(); }

	@Post("/echo") public Map<String,Object> echo(@Body Map<String,Object> payload) { return payload; }
	@Get("/greet") public String greet(@QueryValue(defaultValue="Guest") String name) { return "Hello " + name; }
}

Micronaut Language Guide

Micronaut is a modern, JVM-based full-stack framework for building modular, easily testable microservices and serverless applications. It emphasizes low memory footprint, fast startup, and compile-time dependency injection.

Primary Use Cases

  • ▸Microservices architecture
  • ▸Serverless applications
  • ▸Reactive APIs and streaming services
  • ▸Cloud-native applications with service discovery
  • ▸IoT backends with low memory footprint

Notable Features

  • ▸Compile-time dependency injection
  • ▸Fast startup and low memory footprint
  • ▸Reactive and non-blocking I/O
  • ▸Cloud-native support (Kubernetes, AWS Lambda, etc.)
  • ▸AOP and declarative HTTP clients

Origin & Creator

Micronaut was created by Object Computing, Inc. (OCI), with Graeme Rocher as the lead architect, first released in 2018.

Industrial Note

Micronaut is optimized for microservices, serverless deployments, and environments where fast startup, low memory usage, and reactive I/O are critical.

More Micronaut Typing Exercises

Micronaut Simple Counter APIMicronaut Hello World APIMicronaut JSON EchoMicronaut Query Param ExampleMicronaut Path Variable ExampleMicronaut Async Endpoint ExampleMicronaut Custom 404 ResponseMicronaut Health Check EndpointMicronaut JSON Post Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher