Skip to main content

Connect Dapr SDKs to Catalyst APIs

The Catalyst APIs are Dapr-compatible, meaning they can be invoked using the open-source Dapr SDKs. The Dapr SDKs provide the easiest path for you to get up and running with the Catalyst APIs from your application code.

Dapr provides stable Client SDKs for the following languages, which can be used to communicate with the Catalyst APIs:

Dapr also provides a set of Workflow SDKs for .NET, Python and Java. Only the .NET SDK is currently supported for use with the Catalyst Workflow APIs:

For requests sent to your applications from Catalyst, you may find it useful to leverage the server extension packages Dapr provides. However, ❌ programmatic subscription support via the SDKs is not supported when using the Catalyst Pub/Sub API.

Install the Dapr language SDKS

The below instructions cover how to download the various language SDKs depending on the needs of your application.

Nuget packages are published after every Dapr release and can be found here.

Prerequisites: .NET Core 3.1 or .NET 5+

# Install Dapr client SDK
dotnet add package Dapr.Client

# Install Dapr workflow SDK
dotnet add package Dapr.Workflow

# Install Dapr callback SDK
dotnet add package Dapr.AspNetCore

Configure the Dapr Client

By default, the Dapr SDKs will attempt to connect to a local Dapr process and access the Dapr OSS APIs on http://localhost without authentication. To configure the SDK to interact with the remote Catalyst APIs, you need set the Dapr host endpoint as your Catalyst project endpoint using one of the environment variables below. These are automatically picked up by the SDKs and enable a seamless experience connecting to the Catalyst APIs.

info

All Dapr SDKs use the gRPC protocol by default, except for JavaScript, which uses HTTP.

export DAPR_HTTP_ENDPOINT=$(diagrid project get -o json | jq -r '.status.endpoints.http.url')
export DAPR_GRPC_ENDPOINT=$(diagrid project get -o json | jq -r '.status.endpoints.grpc.url')

In addition to configuring the Dapr host endpoint, you will also need to provide your application with the API token of its associated App ID. This API Token will be sent to the Catalyst APIs as the dapr-api-token request header for authentication and request routing. Below shows an example of retrieving the API token for the App ID, my-appid.

daigrid appid create my-appid
export DAPR_API_TOKEN=$(diagrid appid get my-appid -o json | jq -r '.status.apiToken')

Most Dapr SDKs will pick up the following environment variables as part of the client build process to connect to Diagrid Catalyst without the need to pass them explicitly to the client constructor.

  • DAPR_HTTP_ENDPOINT: Your Catalyst project HTTP endpoint
  • DAPR_GRPC_ENDPOINT: Your Catalyst project gRPC endpoint
  • DAPR_API_TOKEN: The API Token for your application's associated Catalyst App ID

After configuring these environment variables, you can proceed to develop against the Catalyst APIs without any local Dapr dependencies.

When using .NET, a DaprClient can be configured by invoking methods on the DaprClientBuilder class before calling .Build() to create the client.

import Dapr.Client; 

var daprClient = new DaprClientBuilder()
.UseJsonSerializerSettings( ... ) // Configure JSON serializer
.Build();

For more details on how to configure and leverage the .NET SDK, visit the Dapr SDK documentation.

Next Steps

For examples on how you can use the Dapr Client with the Catalyst APIs, refer to the Catalyst Samples GitHub repository or run one of the following tutorials in the language of your choice: