Skip to main content

C#

Start with the gRPC guide to create a Platform API token and download platform.proto. Run the commands below from the directory containing that file.

Create a .NET console project:

dotnet new console -n ReconstructExample

Enter the project directory:

cd ReconstructExample

Add the gRPC client packages:

dotnet add package Grpc.Net.Client
dotnet add package Grpc.Tools
dotnet add package Google.Protobuf

Copy the downloaded platform.proto into the ReconstructExample directory.

Add this item to the project's .csproj file. Grpc.Tools generates the client when you build:

<ItemGroup>
<Protobuf Include="platform.proto" GrpcServices="Client" />
</ItemGroup>

Use the generated types in Program.cs:

using Cr.Reconstruct.External.Grpc;
using Grpc.Core;
using Grpc.Net.Client;

var token = Environment.GetEnvironmentVariable("CR_RECONSTRUCT_API_TOKEN")
?? throw new InvalidOperationException("Set CR_RECONSTRUCT_API_TOKEN.");
var address = Environment.GetEnvironmentVariable("CR_RECONSTRUCT_GRPC_URL")
?? "https://reconstruct.dev";

using var channel = GrpcChannel.ForAddress(address);
var client = new PlatformService.PlatformServiceClient(channel);
var headers = new Metadata { { "authorization", $"Bearer {token}" } };
var page = await client.ListCatalogsAsync(
new ListCatalogsRequest { PageSize = 10 }, headers, deadline: DateTime.UtcNow.AddSeconds(10));

foreach (var catalog in page.Catalogs)
{
var detail = await client.GetCatalogAsync(
new GetCatalogRequest { CatalogId = catalog.CatalogId }, headers);
Console.WriteLine($"{detail.CatalogId}: {detail.Description}");
}

Run dotnet run. The native gRPC channel uses the HTTPS authority; it does not include the REST /api/v1/platform path.