Skip to main content

Connect to Catalyst Project from Dapr SDKs

The Catalyst APIs are Dapr-compatible, meaning they can be invoked using the open-source Dapr SDKs. The Dapr SDKs provide the easiest path 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 in addition to the client SDKs. Only the Python, .NET, Java and Go SDKs are currently supported for use with the Catalyst Workflow API:

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 are not supported ❌ with 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 5+

# Install Dapr client SDK
dotnet add package Dapr.Client

# Install Dapr server SDK
dotnet add package Dapr.AspNetCore

# Install Dapr workflow SDK
dotnet add package Dapr.Workflow

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.

diagrid 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 API Reference documentation.