
# C# {/* #c */}

Comece pelo [guia gRPC](/docs/pt/api/grpc) para criar token API e baixar `platform.proto`. Execute os comandos no diretório desse arquivo.

Crie um projeto de console .NET:

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

Entre no diretório do projeto:

```bash
cd ReconstructExample
```

Adicione os pacotes de cliente gRPC:

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

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

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

Copie o `platform.proto` baixado para `ReconstructExample`.

Adicione este item ao `.csproj`. `Grpc.Tools` gera o cliente durante a compilação:

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

Use os tipos gerados em `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}");
}
```

Execute `dotnet run`. O canal gRPC nativo usa a autoridade HTTPS; não inclui o caminho REST `/api/v1/platform`.
