Arkn.Http 0.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Arkn.Http --version 0.1.4
                    
NuGet\Install-Package Arkn.Http -Version 0.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Arkn.Http" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Arkn.Http" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Arkn.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Arkn.Http --version 0.1.4
                    
#r "nuget: Arkn.Http, 0.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Arkn.Http@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Arkn.Http&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Arkn.Http&version=0.1.4
                    
Install as a Cake Tool

Arkn.Http

Conventions you can read. Patterns you can enforce.

Fluent typed HTTP client where every call returns Result<T>. Built-in retry, timeout, and pluggable auth interceptors. No raw HttpClient.

Install

dotnet add package Arkn.Http

Quick example

// Define your typed client — minimal boilerplate
public class UserApiClient(IArknHttp http) : ArknHttpClient(http, "https://api.example.com")
{
    public Task<Result<User>>   GetAsync(Guid id)                => GetAs<User>("/users/{id}", id);
    public Task<Result<User>>   CreateAsync(CreateUserRequest r) => PostAs<User>("/users", r);
    public Task<Result<User>>   UpdateAsync(Guid id, UpdateUserRequest r) => PutAs<User>("/users/{id}", r, id);
    public Task<Result>         DeleteAsync(Guid id)             => Delete("/users/{id}", id);
}

// Register
builder.Services.AddArknHttp<UserApiClient>("https://api.example.com")
    .WithRetry(maxAttempts: 3)
    .WithTimeout(TimeSpan.FromSeconds(15));

Shorthand methods

ArknHttpClient exposes concise protected methods — no more .Request().Verb().As<T>() chains:

GetAs<T>(path, args)          // GET → Result<T>
PostAs<T>(path, body)         // POST → Result<T>
PutAs<T>(path, body, args)    // PUT → Result<T>
PatchAs<T>(path, body, args)  // PATCH → Result<T>
Delete(path, args)            // DELETE → Result

Get(path, args)               // GET → Result (no body)
Post(path, body)              // POST → Result (no body)
Put(path, body, args)         // PUT → Result (no body)

Auth interceptors

Bearer token (custom factory)

builder.Services.AddArknHttp<UserApiClient>("https://api.example.com")
    .WithBearerAuth(async () =>
    {
        // Called once; token cached in InMemoryTokenStore for 55 min
        return await myAuthService.GetAccessTokenAsync();
    });

OAuth2 Client Credentials (built-in, zero external deps)

builder.Services.AddArknHttp<UserApiClient>("https://api.example.com")
    .WithClientCredentials(opts =>
    {
        opts.TokenUrl     = "https://auth.example.com/oauth/token";
        opts.ClientId     = "my-client";
        opts.ClientSecret = config["Auth:Secret"];
        opts.Scope        = "api.read api.write";
    });

The ClientCredentialsInterceptor fetches a token via POST to TokenUrl, caches it using InMemoryTokenStore (with buffer of 30s before expiry), and attaches it as Authorization: Bearer <token> on every request.

Custom interceptor

public sealed class ApiKeyInterceptor : IArknAuthInterceptor
{
    private readonly string _key;
    public ApiKeyInterceptor(string key) => _key = key;

    public Task ApplyAsync(HttpRequestMessage req, CancellationToken ct = default)
    {
        req.Headers.Add("X-Api-Key", _key);
        return Task.CompletedTask;
    }
}

builder.Services.AddArknHttp<UserApiClient>("https://api.example.com")
    .WithInterceptor(new ApiKeyInterceptor(config["ApiKey"]));

Token store

InMemoryTokenStore is registered as a singleton automatically when any auth method is configured. Tokens are cached with a 30-second expiry buffer and can be invalidated manually:

var store = serviceProvider.GetRequiredService<IArknTokenStore>();
await store.InvalidateAsync("my-client_credentials");

Part of the Arkn ecosystem

github.com/fernando-terra/arkn · nuget.org/packages/Arkn.Http

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.2 93 5/30/2026
0.3.1 109 5/28/2026
0.3.0 95 5/6/2026
0.2.0 95 5/6/2026
0.1.6 93 5/4/2026
0.1.5 92 5/4/2026
0.1.4 93 5/4/2026
0.1.3 99 5/4/2026
0.1.2 97 5/4/2026
0.1.1 97 5/4/2026
0.1.0 95 5/4/2026