Class GettingStarted

java.lang.Object
com.commercetools.docs.meta.GettingStarted

public class GettingStarted extends Object
Table of content

About the client

The commercetools Composable Commerce client communicates asynchronously with the API via HTTPS and it takes care about authentication.

The client uses Java objects to formulate an HTTP request, performs the request and maps the JSON response into a Java object. Since the client is thread-safe you need only one client to perform multiple requests in parallel.

Instantiation

Creating an instance for a project:

// ApiRoot config for Europe projects
ApiRoot apiRoot = ApiRootBuilder.of()
        .defaultClient(ClientCredentials.of()
                .withClientId("your-client-id")
                .withClientSecret("your-client-secret")
                .build(),
            ServiceRegion.GCP_EUROPE_WEST1)
        .build();

// Project scoped ApiRoot config for Europe projects
ProjectApiRoot projectApiRoot = ApiRootBuilder.of()
        .defaultClient(ClientCredentials.of()
                .withClientId("your-client-id")
                .withClientSecret("your-client-secret")
                .build(),
            ServiceRegion.GCP_EUROPE_WEST1)
        .build("my-project");

// Project scoped ApiRoot config for Europe projects
ProjectApiRoot projectApiRootGcpEu = ApiRootBuilder.of()
        .defaultClient(ClientCredentials.of()
                .withClientId("your-client-id")
                .withClientSecret("your-client-secret")
                .build(),
            ServiceRegion.valueOf("GCP_EUROPE_WEST1"))
        .build("my-project");

See the test code.

Performing requests

A client works on the abstraction level of one HTTP request. With one client you can start multiple requests in parallel, it is thread-safe.

Example

ProjectApiRoot apiRoot = createProjectClient();
final CompletableFuture<ApiHttpResponse<TaxCategoryPagedQueryResponse>> future = apiRoot.taxCategories()
        .get()
        .withWhere("name = :name")
        .withPredicateVar("name", "de19")
        .execute();

See the test code.

Closing the client

The client holds resources like thread pools and IO connections, so call close() to release them.

  • Constructor Details

    • GettingStarted

      public GettingStarted()