.NET SDK
The official Oproto SDK for C# and .NET applications.
Installation
dotnet add package Oproto.Sdk
Or via the NuGet Package Manager:
Install-Package Oproto.Sdk
Requirements
- .NET 8.0 or later
- Compatible with Native AOT
Quick Start
using Oproto.Sdk;
// Initialize the client
var client = new OprotoClient(options =>
{
options.AccessToken = "your-access-token";
});
// Make API calls
var companies = await client.Companies.ListAsync();
Dependency Injection
Register the SDK with your DI container:
// Program.cs or Startup.cs
builder.Services.AddOprotoClient(options =>
{
options.AccessToken = configuration["Oproto:AccessToken"];
});
// Inject and use
public class MyService
{
private readonly IOprotoClient _client;
public MyService(IOprotoClient client)
{
_client = client;
}
public async Task DoWorkAsync()
{
var companies = await _client.Companies.ListAsync();
}
}
Authentication
The SDK supports OAuth 2.0 authentication:
Access Token
var client = new OprotoClient(options =>
{
options.AccessToken = "your-access-token";
});
Token Refresh
For long-running applications, configure automatic token refresh:
var client = new OprotoClient(options =>
{
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.TokenEndpoint = "https://auth.oproto.io/oauth/token";
});
Configuration Options
| Option | Type | Description |
|---|---|---|
AccessToken | string | OAuth access token |
ClientId | string | OAuth client ID for token refresh |
ClientSecret | string | OAuth client secret for token refresh |
BaseUrl | string | API base URL (defaults to production) |
Timeout | TimeSpan | Request timeout |
Error Handling
The SDK throws typed exceptions for API failures:
using Oproto.Sdk;
using Oproto.Sdk.Exceptions;
try
{
var company = await client.Companies.GetAsync("invalid-id");
}
catch (OprotoApiException ex)
{
Console.WriteLine($"API Error: {ex.ErrorCode} - {ex.Message}");
}
Native AOT Support
The SDK is fully compatible with Native AOT compilation. No additional configuration is required.
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>