Skip to content

Make RestClient easier to use #823

Description

@jianghaolu

There are 3 major use cases for RestClient that are listed in the order of priority:

  • Developers for data planes want to customize HTTP & REST configurations
  • Developers for management planes want to reuse HTTP client and configurations across multiple services
  • Developers for management planes that are not yet converted to fluent

For these use cases, there are following inconveniences:

  • RestClient.Builder asks for base URL, which developers need to look into implementation to know, especially for dynamic base URLs
  • RestClient.Builder requires a call of .withMapperAdapter() which is unknown to developers

The proposal

Data plane usage

  1. Basic scenario
PetDataPlaneClient client = new PetDataPlaneClientImpl(credentials);
  1. For working with non-standard environments
PetDataPlaneClient client = new PetDataPlaneClientImpl(AzureEnvironment.AzureChinaCloud, credentials);
PetDataPlaneClient client = new PetDataPlaneClientImpl("azurestack.contoso.com", credentials);
  1. For advanced scenario
RestClient restClient = new RestClient.Builder()
        .withDefaultBaseUrl(PetDataPlaneClient.class)
        .withCredentials(credentials)
        .withReadTimeout(5, TimeUnit.Minutes)
        .withUserAgent("Contoso")
        .build();
PetDataPlaneClient client = new PetDataPlaneClientImpl(restClient);

Management plane usage

  1. Basic scenario
PetManager petManager = PetManager.authenticate(credentials);
  1. Advanced scenario
RestClient restClient = new RestClient.Builder()
        .withDefaultBaseUrl(AzureEnvironment.Azure)
        .withCredentials(credentials)
        .withUserAgent("Contoso")
        .build();
PetManager petManager = PetManager.authenticate(restClient);
ProduceManager produceManager = ProduceManager.authenticate(restClient);

Management plane, without fluent interface

  1. Basic scenario
PetManagementClient petClient = new PetDataPlaneClientImpl(credentials);
  1. Advanced scenario
RestClient restClient = new RestClient.Builder()
        .withDefaultBaseUrl(AzureEnvironment.Azure)
        .withCredentials(credentials)
        .withUserAgent("Contoso")
        .build();
PetManagementClient petClient = new PetDataPlaneClientImpl(restClient);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions