
# C# {/* #c */}

Platform API 토큰을 만들고 `platform.proto`를 받으려면 [gRPC 가이드](/docs/ko/api/grpc)부터 시작하세요. 아래 명령은 해당 파일이 있는 디렉터리에서 실행하세요.

.NET 콘솔 프로젝트를 만드세요:

```bash
dotnet new console -n ReconstructExample
```

프로젝트 디렉터리로 이동하세요:

```bash
cd ReconstructExample
```

gRPC 클라이언트 패키지를 추가하세요:

```bash
dotnet add package Grpc.Net.Client
```

```bash
dotnet add package Grpc.Tools
```

```bash
dotnet add package Google.Protobuf
```

다운로드한 `platform.proto`를 `ReconstructExample` 디렉터리에 복사하세요.

프로젝트 `.csproj` 파일에 다음 항목을 추가하세요. 빌드할 때 `Grpc.Tools`가 클라이언트를 생성합니다:

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

생성된 형식을 `Program.cs`에서 사용하세요:

```csharp
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`을 실행하세요. 네이티브 gRPC 채널은 HTTPS authority를 사용하며 REST 경로 `/api/v1/platform`은 포함하지 않습니다.
