Skip to content

[Feature] Add DaprClient.invokeHttpClient(appId) factory for service invocation #1743

@javier-aliaga

Description

@javier-aliaga

Summary

Add DaprClient.invokeHttpClient(appId) — an SDK-native factory that returns an HTTP client preconfigured for Dapr service invocation, as the successor to the invokeMethod(...) overloads deprecated by #1666.

Motivation

After #1666, every DaprClient.invokeMethod(...) overload is @Deprecated, with the javadoc telling users to "use language-native HTTP clients or gRPC clients for service invocation instead." However, the SDK provides no SDK-native replacement, so any user who wants to keep going through DaprClient must hand-roll:

  • Dapr endpoint/port resolution,
  • /v1.0/invoke/<app-id>/method/<method> URL composition,
  • dapr-api-token header injection,
  • and the lifecycle of their own java.net.http.HttpClient.

The .NET SDK already solves this with DaprClient.CreateInvokeHttpClient(appId), which returns a System.Net.Http.HttpClient whose BaseAddress is the Dapr invoke prefix for the target app and which auto-attaches the api token — letting users write await httpClient.GetAsync("weatherforecast") directly.

Proposed API

DaprInvokeHttpClient invoker = daprClient.invokeHttpClient("orderprocessor");

HttpRequest request = invoker.newRequestBuilder("orders")
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(json))
    .build();

HttpResponse<String> response = invoker.send(request, HttpResponse.BodyHandlers.ofString());

The returned DaprInvokeHttpClient:

  • resolves relative paths against {daprHttpEndpoint}/v1.0/invoke/{appId}/method/,
  • attaches the dapr-api-token header when configured,
  • reuses the SDK's shared java.net.http.HttpClient (no extra lifecycle for the caller),
  • and exposes the underlying httpClient() and baseUri() as escape hatches.

References

Release Note

RELEASE NOTE: ADD DaprClient.invokeHttpClient(appId) factory — an SDK-native HTTP client preconfigured for service invocation, mirroring .NET's CreateInvokeHttpClient and serving as the successor to the deprecated invokeMethod APIs.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions