Are you an LLM? You can read better optimized documentation at /guide/extensions/apiclient.md for this page in Markdown format
API Client
The API Client module provides a declarative RESTful client for Wow services based on CoApi. It offers both reactive and synchronous interfaces for sending commands and querying snapshots.
Features
- Reactive and Synchronous APIs — Choose between
Mono-based reactive or blocking synchronous interfaces - Service Discovery — Built-in support via
@CoApiand@LoadBalancedannotations - Command Gateway — Send commands with wait strategies through REST endpoints
- Snapshot Query — Single, list, paged, and count query interfaces
Installation
Add the wow-apiclient dependency:
kotlin
implementation("me.ahoo.wow:wow-apiclient")Command Gateway
Reactive Command Gateway
kotlin
@CoApi
interface OrderCommandGateway : ReactiveRestCommandGateway<Mono<CommandResult>, CommandResult>Send a command:
kotlin
val request = CommandRequest(
body = CreateOrder(orderId = "order-001", items = listOf(...)),
waitStrategy = WaitStrategy.projected()
)
val result = orderCommandGateway.send(request).block()Synchronous Command Gateway
kotlin
@CoApi
interface OrderCommandGateway : SyncRestCommandGateway<CommandResult, CommandResult>Snapshot Query
Reactive Query API
kotlin
@CoApi
interface OrderQueryApi : ReactiveSnapshotQueryApi<OrderState>Provides single, list, paged, and count query methods:
kotlin
val order = queryApi.getById("order-001").block()
val paged = queryApi.paged(PagedQuery(pageIndex = 0, pageSize = 10)).block()
val count = queryApi.count().block()Synchronous Query API
kotlin
@CoApi
interface OrderQueryApi : SynchronousSnapshotQueryApi<OrderState>Error Handling
RestCommandGatewayException wraps command errors with full request context:
kotlin
try {
orderCommandGateway.send(request).block()
} catch (ex: RestCommandGatewayException) {
println("Command failed: ${ex.message}")
}