ControlR.ApiClient
0.20.82-dev
See the version list below for details.
dotnet add package ControlR.ApiClient --version 0.20.82-dev
NuGet\Install-Package ControlR.ApiClient -Version 0.20.82-dev
<PackageReference Include="ControlR.ApiClient" Version="0.20.82-dev" />
<PackageVersion Include="ControlR.ApiClient" Version="0.20.82-dev" />
<PackageReference Include="ControlR.ApiClient" />
paket add ControlR.ApiClient --version 0.20.82-dev
#r "nuget: ControlR.ApiClient, 0.20.82-dev"
#:package ControlR.ApiClient@0.20.82-dev
#addin nuget:?package=ControlR.ApiClient&version=0.20.82-dev&prerelease
#tool nuget:?package=ControlR.ApiClient&version=0.20.82-dev&prerelease
ControlR API Client
A .NET client library for interacting with the ControlR API. This library provides a strongly-typed interface for making API calls to the backend of a ControlR server.
Features
- Strongly-typed API client generated from OpenAPI specification
- Built-in support for dependency injection
- Static builder pattern for scenarios where dependency injection is not available
- Efficient HTTP connection management via
IHttpClientFactory - Automatic request/response serialization
Installation
dotnet add package ControlR.ApiClient
Quick Start
The library supports two usage patterns: dependency injection (recommended for most applications) and a static builder pattern (useful for scripts or simple scenarios).
Option 1: Dependency Injection
Service Registration
Configure the client in your Program.cs or startup file:
using ControlR.ApiClient;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddControlrApiClient(options =>
{
options.BaseUrl = new Uri("https://your-controlr-server.com");
options.PersonalAccessToken = "your-personal-access-token";
});
You can also load options from configuration using the overload that accepts IConfiguration:
using ControlR.ApiClient;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddControlrApiClient(
builder.Configuration,
ControlrApiClientOptions.SectionKey);
With the following configuration in appsettings.json:
{
"ControlrApiClient": {
"BaseUrl": "https://your-controlr-server.com",
"PersonalAccessToken": "your-personal-access-token"
}
}
Using the Client
Inject IControlrApi directly into your services:
using ControlR.ApiClient;
public class MyService
{
private readonly IControlrApi _client;
private readonly ILogger<MyService> _logger;
public MyService(IControlrApi client, ILogger<MyService> logger)
{
_client = client;
_logger = logger;
}
public async Task GetDevicesAsync(CancellationToken cancellationToken)
{
var devices = new List<DeviceResponseDto>();
await foreach (var device in _client.Devices.GetAllDevices(cancellationToken).WithCancellation(cancellationToken))
{
devices.Add(device);
}
_logger.LogInformation("Retrieved {DeviceCount} devices.", devices.Count);
foreach (var device in devices)
{
_logger.LogInformation(" - {DeviceName} (ID: {DeviceId})", device.Name, device.Id);
}
}
}
Option 2: Static Builder
The static builder pattern is useful for console applications, scripts, or scenarios where you prefer not to use dependency injection.
Initialization
Initialize the builder once at application startup:
using ControlR.ApiClient;
ControlrApiClientBuilder.Initialize(options =>
{
options.BaseUrl = new Uri("https://your-controlr-server.com");
options.PersonalAccessToken = "your-personal-access-token";
});
Using the Client
Get a client instance whenever needed:
var client = ControlrApiClientBuilder.GetClient();
var devices = new List<DeviceResponseDto>();
await foreach (var device in client.Devices.GetAllDevices(cancellationToken).WithCancellation(cancellationToken))
{
devices.Add(device);
}
Console.WriteLine($"Retrieved {devices.Count} devices.");
foreach (var device in devices)
{
Console.WriteLine($" - {device.Name} (ID: {device.Id})");
}
Configuration
ControlrApiClientOptions
| Property | Type | Required | Description |
|---|---|---|---|
BaseUrl |
Uri |
Yes | The base URL of your ControlR server |
PersonalAccessToken |
string |
Yes | Your personal access token for authentication |
Obtaining a Personal Access Token
- Log in to your ControlR server
- Navigate to your account settings
- Generate a new Personal Access Token
- Store it securely (e.g., using User Secrets in development or secure configuration in production)
How It Works
IHttpClientFactory Integration
The ControlR API Client uses IHttpClientFactory under the hood to manage HttpClient instances. This provides several benefits:
- Prevents socket exhaustion: Automatically manages the lifecycle of HTTP connections
- Handles DNS changes: Respects DNS TTL by periodically recycling connections
- Efficient resource usage: Pools and reuses connections
- Handler pipeline: Supports middleware-style message handlers for cross-cutting concerns
This means you can safely create multiple client instances without worrying about common pitfalls associated with direct HttpClient usage.
Example Project
For a complete working example, see the ControlR.ApiClientExample project in this repository.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ControlR.Libraries.Api.Contracts (>= 0.20.82-dev)
- ControlR.Libraries.DataRedaction (>= 0.20.82-dev)
- Microsoft.Extensions.Compliance.Redaction (>= 10.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ControlR.ApiClient:
| Package | Downloads |
|---|---|
|
ControlR.Viewer.Avalonia
Open-source remote control and remote access. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.20.86 | 36 | 3/5/2026 |
| 0.20.85 | 34 | 3/4/2026 |
| 0.20.84-dev | 32 | 3/4/2026 |
| 0.20.82-dev | 35 | 3/4/2026 |
| 0.20.79-dev | 32 | 3/3/2026 |
| 0.19.2 | 134 | 1/27/2026 |
| 0.18.22 | 141 | 1/12/2026 |
| 0.17.20 | 133 | 12/31/2025 |
| 0.17.19-dev | 101 | 12/31/2025 |
| 0.17.17 | 100 | 12/31/2025 |