C#
Platform API belirteci oluşturmak ve platform.proto indirmek için gRPC kılavuzuyla başlayın. Aşağıdaki komutları bu dosyanın bulunduğu dizinden çalıştırın.
Bir .NET konsol projesi oluşturun:
dotnet new console -n ReconstructExample
Proje dizinine girin:
cd ReconstructExample
gRPC istemci paketlerini ekleyin:
dotnet add package Grpc.Net.Client
dotnet add package Grpc.Tools
dotnet add package Google.Protobuf
İndirilen platform.proto dosyasını ReconstructExample dizinine kopyalayın.
Projenin .csproj dosyasına bu öğeyi ekleyin. Derleme sırasında Grpc.Tools istemciyi oluşturur:
<ItemGroup>
<Protobuf Include="platform.proto" GrpcServices="Client" />
</ItemGroup>
Oluşturulan türleri Program.cs içinde kullanın:
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}");
}
dotnet run çalıştırın. Yerel gRPC kanalı HTTPS authority adresini kullanır; REST /api/v1/platform yolunu içermez.