C# SDK

Jaina.Client — .NET / Unity client targeting netstandard2.0.

Install

dotnet add package Jaina.Client

For Unity, download the DLL from NuGet and drop into Assets/Plugins/. Set the meta to Any Platform.

Quickstart

using Jaina.Client;

var client = new JainaClient(apiKey: System.Environment.GetEnvironmentVariable("JAINA_API_KEY"));

var projects = await client.Projects.ListAsync();
foreach (var p in projects.Items)
{
    System.Console.WriteLine(p.Slug);
}

Typed records

public class Enemy
{
    public string Name { get; set; }
    public int Hp { get; set; }
    public int Attack { get; set; }
    public string Sprite { get; set; }
    public string Rarity { get; set; }
}

var enemies = await client.Records.ListAsync<Enemy>("my-game", "enemy", new ListOptions {
    Filter = new { hp = new { gte = 50 } }
});

foreach (var e in enemies.Items)
{
    System.Console.WriteLine($"{e.Name} (HP {e.Hp})");
}

Generate the POCO with jaina codegen --lang csharp.

CancellationToken

Every async method accepts a CancellationToken:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var enemies = await client.Records.ListAsync<Enemy>("my-game", "enemy", cancellationToken: cts.Token);

IDisposable

JainaClient implements IDisposable. In typical app patterns, wrap with using or register as a singleton in DI.

using var client = new JainaClient(apiKey: "...");

Unity gotchas

  • Newtonsoft.Json is required (already in Unity 2020+). The SDK uses it for serialization.
  • Async/await in Unity requires UniTask or Task interop. Both work.
  • WebGL builds: requests use UnityWebRequest under the hood. CORS applies — your Jaina API must allow your game's origin.

Error handling

try
{
    await client.Records.CreateAsync("my-game", "enemy", new { name = "Goblin" });
}
catch (JainaApiException ex)
{
    Console.WriteLine($"{ex.Status} {ex.Code}: {ex.Message}");
}