Java / Micronaut Interview questions
What is the Micronaut HTTP Client?
The Micronaut HTTP Client is a built-in, non-blocking client for calling other HTTP services, available in both a low-level programmatic form and a declarative form.
The low-level HttpClient is injected and used directly:
@Inject HttpClient httpClient; Mono<String> result = Mono.from( httpClient.retrieve("/status"));
The declarative form, using @Client, is more commonly used day-to-day: you define an interface with HTTP-annotated methods, and Micronaut generates the implementation at compile time.
@Client("https://payments.internal") public interface PaymentClient { @Get("/status/{id}") Mono<Status> getStatus(String id); }
Both are backed by Netty and integrate with service discovery, so a @Client("payments-service") can resolve to a load-balanced instance rather than a hardcoded URL.
More Related questions...