Class Features
Features
Embracing Java 8
The SDK API uses:
CompletionStage
- Java Date API:
ZonedDateTime
,LocalDate
andLocalTime
functional interfaces
Request builders
The SDK provides a request builder which allows to explore the API while writing the program.
ProjectApiRoot apiRoot = createProjectClient();
final CompletableFuture<ApiHttpResponse<TaxCategoryPagedQueryResponse>> future = apiRoot.taxCategories()
.get()
.withWhere("name = :name")
.withPredicateVar("name", "de19")
.execute();
See the test code.
The request method objects are immutable as shown in this example.
ProjectApiRoot apiRoot = createProjectClient();
final ByProjectKeyTaxCategoriesGet taxCategoriesGet = apiRoot.taxCategories()
.get()
.withWhere("name = :name")
.withPredicateVar("name", "de19");
final ByProjectKeyTaxCategoriesGet taxCategoriesGet2 = taxCategoriesGet.withPredicateVar("name", "de07");
Assertions.assertThat(taxCategoriesGet.getQueryParam("var.name").get(0)).isEqualTo("de19");
Assertions.assertThat(taxCategoriesGet2.getQueryParam("var.name").get(0)).isEqualTo("de07");
See the test code.
Good defaults for equals() and hashCode()
The SDK's model implementation classes provide default implementations for the methods.
Client interfaces
The HTTP client abstract itself is a functional interface and can be replaced with test doubles.
Model factory methods
Each model has a factory method ::of()
to create a new empty instance. The method ::builder()
returns a new builder instance.
Middlewares
The client supports middlewares to adjust request and responses while being executed.
A middleware
is a functional interface
which has the request and the next middleware as an argument and returns a CompletableFuture with the response. The following
example shows how to add an additional header.
ProjectApiRoot apiRoot = ApiRootBuilder.of()
.defaultClient(ClientCredentials.of()
.withClientId("your-client-id")
.withClientSecret("your-client-secret")
.withScopes("your-scopes")
.build(),
ServiceRegion.GCP_EUROPE_WEST1)
.addMiddleware((request, next) -> next.apply(request.addHeader("X-FOO", "Bar")))
.build("my-project");
See the test code.
The authentication, logging and other functionality has been implemented in middlewares and is added by default to the HandlerStack
in the ClientBuilder
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Features
public Features()
-