Skip to content

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.

ModuleDemonstrates
example-provider-apiShared contract: TodoApi (@HttpExchange) and TodoClient : TodoApi (@CoApi(serviceId = "provider-service")), depending only on coapi-api
example-provider-serverProvider implementing TodoApi in a @RestController (port 8010)
example-consumer-clientClient library: placeholder baseUrl, serviceId with custom name, per-client filters, a client without base URL taking URI/UriBuilderFactory
example-consumer-serverReactive consumer: @EnableCoApi plus coapi.base-packages, static discovery instances, filters by bean name and by type, a per-client connection pool customizer
example-syncSynchronous 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:test

To 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 ​

PatternPage
Shared provider/consumer contractDefining Clients
Clients from another moduleRegistering Clients
Filters by name/type, connection pool customizerCustomization
serviceId with static instancesLoad Balancing
Sync clients in JavaClient Modes