Skip to content

Installation & Setup

Requirements

  • .NET 10.0 or later
  • Akka.NET is pulled in as a transitive dependency — no manual installation needed

Install the Package

bash
dotnet add package TurboHTTP

Or add it to your .csproj:

xml
<PackageReference Include="TurboHTTP" Version="1.*" />

Register TurboHTTP in your IServiceCollection:

csharp
using TurboHTTP;

var builder = WebApplication.CreateBuilder(args);

// Register a default client
builder.Services.AddTurboHttpClient(options =>
{
    options.BaseAddress = new Uri("https://api.example.com");
});

var app = builder.Build();

Inject ITurboHttpClientFactory into your services:

csharp
public sealed class OrderService
{
    private readonly ITurboHttpClient _client;

    public OrderService(ITurboHttpClientFactory factory)
    {
        _client = factory.CreateClient();
    }

    public async Task<Order> GetOrderAsync(int id, CancellationToken ct)
    {
        var request = new HttpRequestMessage(HttpMethod.Get, $"/orders/{id}");
        var response = await _client.SendAsync(request, ct);
        response.EnsureSuccessStatusCode();
        return await response.Content.ReadFromJsonAsync<Order>(ct);
    }
}

Named Clients

Register multiple clients with different configurations:

csharp
// Public API — caching enabled
builder.Services.AddTurboHttpClient("public-api", options =>
{
    options.BaseAddress = new Uri("https://api.example.com");
})
.WithCache();

// Internal service — aggressive retries
builder.Services.AddTurboHttpClient("internal", options =>
{
    options.BaseAddress = new Uri("http://internal-service:8080");
})
.WithRetry(retry => { retry.MaxRetries = 5; });

Resolve by name:

csharp
public sealed class GatewayService
{
    private readonly ITurboHttpClient _publicApi;
    private readonly ITurboHttpClient _internal;

    public GatewayService(ITurboHttpClientFactory factory)
    {
        _publicApi = factory.CreateClient("public-api");
        _internal = factory.CreateClient("internal");
    }
}

Typed Clients

Bind a client directly to a service class:

csharp
builder.Services.AddTurboHttpClient<OrderService>(options =>
{
    options.BaseAddress = new Uri("https://api.example.com");
})
.WithRetry();

The DI container injects ITurboHttpClient into OrderService automatically.

Fluent Builder API

Use the builder pattern to compose features:

csharp
builder.Services.AddTurboHttpClient("full-featured", options =>
{
    options.BaseAddress = new Uri("https://api.example.com");
})
.WithRedirect()              // follow redirects (default settings)
.WithRetry()                 // automatic retries
.WithCookies()               // automatic cookie management
.WithCache()                 // HTTP caching
.WithDecompression(true);    // gzip/deflate/brotli

Minimal Example

A complete console application using the DI-based approach:

csharp
using TurboHTTP;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddTurboHttpClient(options =>
{
    options.BaseAddress = new Uri("https://jsonplaceholder.typicode.com");
});

var provider = services.BuildServiceProvider();
var factory = provider.GetRequiredService<ITurboHttpClientFactory>();
using var client = factory.CreateClient();

var request = new HttpRequestMessage(HttpMethod.Get, "/posts/1");
var response = await client.SendAsync(request, CancellationToken.None);

Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine(await response.Content.ReadAsStringAsync());

WARNING

Always dispose the client when done to ensure connections are properly cleaned up.

Next Steps

Released under the MIT License.