Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Micronaut REST API with a counter using Controller and in-memory state.
import io.micronaut.http.annotation.*;
import javax.inject.Singleton;
@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("/counter")
class CounterController {
private final CounterService service;
CounterController(CounterService service) {
this.service = service;
}
@Get
public int getCount() { return service.getCount(); }
@Post("/increment")
public int increment() { return service.increment(); }
@Post("/decrement")
public int decrement() { return service.decrement(); }
@Post("/reset")
public int reset() { return service.reset(); }
}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.
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.