kontent-ai / kontent-ai/java-packages

Add synchronous support to the DeliveryClient

Open
#109 6 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue groomed hacktoberfest help wanted up-for-grabs
Dominant language
Java
Stars
17
Forks
27
PR merge metrics
No merged PRs in 30d

Description

### Motivation

After updating a large application to the latest version of the Java SDK, all calls to the DeliveryClient had to wrapped in a synchronous wrapper. It would be helpful if there were a built-in way to call the DeliveryClient synchronously rather than introducing additional code to the project.

### Proposed solution

Add alternate methods for working with the DeliveryClient synchronously, for example:

`deliveryClient.getItems().toSync()` or `deliveryClient.getItemsSynchronously()`

### Additional context

Here is the wrapper class that I had to write:

```
public class DeliveryClientHelper {
public static T toSync(CompletionStage completionStage) {
try {
return completionStage.toCompletableFuture().get();
} catch (InterruptedException e) {
log.error("Error converting completion stage: {}", e.getMessage());
} catch (ExecutionException e) {
log.error("Error converting completion stage: {}", e.getMessage());
}
return null;
}
}

```

An example call using the wrapper:

```
List blogHomepages = DeliveryClientHelper.toSync(deliveryClient.getItems(AgencySiteBlogLanding.class));
```

An ideal way to use the DeliveryClient

```
List blogHomepages = deliveryClient.getItems(AgencySiteBlogLanding.class).toSync();
```

Contributor guide

Open the contributing guide

Research direction

Start by reading the DeliveryClient methods and the CompletionStage-based return values described in the issue, then compare them with the provided DeliveryClientHelper wrapper. Define how synchronous alternatives should expose results and failures, and consider the example calls as the completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.