C#
Start with the REST guide to create a Platform API token. This example uses HttpClient and the built-in JSON APIs; no generated gRPC client is required.
Create a console project:
dotnet new console -n ReconstructRestExample
Enter the project directory:
cd ReconstructRestExample
Use this Program.cs:
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
var token = Environment.GetEnvironmentVariable("CR_RECONSTRUCT_API_TOKEN")
?? throw new InvalidOperationException("Set CR_RECONSTRUCT_API_TOKEN.");
var baseUrl = Environment.GetEnvironmentVariable("CR_RECONSTRUCT_REST_URL")
?? "https://reconstruct.dev/api/v1/platform";
using var client = new HttpClient { BaseAddress = new Uri(baseUrl.TrimEnd('/') + "/") };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
using var page = await client.GetFromJsonAsync<JsonDocument>("catalogs?pageSize=10")
?? throw new InvalidOperationException("The catalog response was empty.");
if (page.RootElement.TryGetProperty("catalogs", out var catalogs))
{
foreach (var catalog in catalogs.EnumerateArray())
{
var id = catalog.GetProperty("catalogId").GetString()!;
using var detail = await client.GetFromJsonAsync<JsonDocument>(
"catalogs/" + Uri.EscapeDataString(id))
?? throw new InvalidOperationException("The catalog detail was empty.");
Console.WriteLine($"{id}: {detail.RootElement.GetProperty("description").GetString()}");
}
}
Run dotnet run. If nextPageToken is present in the list response, send it as the URL-encoded pageToken query parameter to continue.