-
Notifications
You must be signed in to change notification settings - Fork 2k
Creating Service Clients
All Azure Java client libraries follow the same API design pattern of offering a Java builder class that is responsible for creating an instance of a client. This separates the definition and instantiation of the client from its operation, allowing the client to be immutable and thus simpler to use. On top of this, all client libraries follow a few important patterns:
-
Client libraries that support both synchronous and asynchronous APIs must offer these in separate classes. This means that in these cases there would be, for example, a
KeyVaultClient
for sync APIs and aKeyVaultAsyncClient
for async APIs. In cases where the client library only offers one type, the same naming pattern is used. -
There is a single builder class that takes responsibility for building both the sync and async APIs. The builder will be named similarly to the sync client class, with
Builder
included. For example,KeyVaultClientBuilder
. This builder will havebuildClient()
andbuildAsyncClient()
methods to create client instances, as appropriate.
Because of these conventions, users of the Java client libraries should feel comfortable that all classes ending in Client
will be immutable and provide operations to interact with an Azure service. All classes that end in ClientBuilder
will provide operations to configure and create an instance of a particular client type.
The code to create a synchronous Key Vault KeyClient
would be similar to the following:
KeyClient client = new KeyClientBuilder()
.endpoint(<your-vault-url>)
.credential(new DefaultAzureCredential())
.buildClient();
Similarly, to create an asynchronous Key Vault KeyAsyncClient
, do the following:
KeyAsyncClient client = new KeyClientBuilder()
.endpoint(<your-vault-url>)
.credential(new DefaultAzureCredential())
.buildAsyncClient();
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers