Examples
The example/ directory has runnable applications. They cover client definition, registration, client modes, load balancing and customization. Authentication is not covered; see Authentication for its samples.
| Module | Demonstrates |
|---|---|
example-provider-api | Shared contract: TodoApi (@HttpExchange) and TodoClient : TodoApi (@CoApi(serviceId = "provider-service")), depending only on coapi-api |
example-provider-server | Provider implementing TodoApi in a @RestController (port 8010) |
example-consumer-client | Client library: placeholder baseUrl, serviceId with custom name, per-client filters, a client without base URL taking URI/UriBuilderFactory |
example-consumer-server | Reactive consumer: @EnableCoApi plus coapi.base-packages, static discovery instances, filters by bean name and by type, a per-client connection pool customizer |
example-sync | Synchronous Java clients (List<Issue> return types) on RestClient, with and without load balancing |
Running them
The tests start each application against local stand-ins, so they need no network:
bash
./gradlew :example-consumer-server:test :example-provider-server:test :example-sync:testTo try the provider/consumer pair by hand, start ProviderServer (port 8010) and ConsumerServer (port 8080) from your IDE, then call GET http://localhost:8080/todo. The consumer resolves provider-service through the simple discovery instances in its application.yaml.
Where each pattern is explained
| Pattern | Page |
|---|---|
| Shared provider/consumer contract | Defining Clients |
| Clients from another module | Registering Clients |
| Filters by name/type, connection pool customizer | Customization |
serviceId with static instances | Load Balancing |
| Sync clients in Java | Client Modes |