mirror of
https://github.com/alexhopeoconnor/binarylane-dotnet.git
synced 2026-10-04 02:18:11 +10:00
1.4 KiB
1.4 KiB
Getting started
BinaryLane.Api connects to BinaryLane's bearer-token v2 API at
https://api.binarylane.com.au/v2/.
1. Install the package
dotnet add package BinaryLane.Api --prerelease
2. Store the token safely
For local development, initialise user secrets for your application and add the token:
dotnet user-secrets init
dotnet user-secrets set "BinaryLane:ApiToken" "your-token"
For hosted applications, use the platform's secret store or supply
BINARYLANE_API_TOKEN at runtime.
3. Register the client
using BinaryLane.Api.V2;
using BinaryLane.Api.V2.DependencyInjection;
using BinaryLane.Api.V2.Models;
builder.Services.AddBinaryLaneApi(options =>
{
options.ApiToken = builder.Configuration["BinaryLane:ApiToken"]
?? Environment.GetEnvironmentVariable("BINARYLANE_API_TOKEN")
?? throw new InvalidOperationException("A BinaryLane API token is required.");
});
4. Make a request
Inject IBinaryLaneClient, then select the resource you need:
public sealed class ServerReader(IBinaryLaneClient binaryLane)
{
public IAsyncEnumerable<Server> ListAsync(CancellationToken cancellationToken) =>
binaryLane.Servers.ListAllAsync(cancellationToken: cancellationToken);
}
See Configuration for custom token providers and Pagination for page-by-page access.