Soenneker.Blazor.ApiClient 11.0.3306

Prefix Reserved
dotnet add package Soenneker.Blazor.ApiClient --version 11.0.3306
                    
NuGet\Install-Package Soenneker.Blazor.ApiClient -Version 11.0.3306
                    
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="Soenneker.Blazor.ApiClient" Version="11.0.3306" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.ApiClient" Version="11.0.3306" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.ApiClient" />
                    
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 Soenneker.Blazor.ApiClient --version 11.0.3306
                    
#r "nuget: Soenneker.Blazor.ApiClient, 11.0.3306"
                    
#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 Soenneker.Blazor.ApiClient@11.0.3306
                    
#: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=Soenneker.Blazor.ApiClient&version=11.0.3306
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.ApiClient&version=11.0.3306
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Blazor.ApiClient

A scoped Blazor API client for JSON requests, authenticated session tokens, optional browser-console logging, and multipart uploads.

Installation and registration

dotnet add package Soenneker.Blazor.ApiClient
using Soenneker.Blazor.ApiClient.Registrars;

builder.Services.AddApiClientAsScoped();

The registrar also adds the session, JSON logging, and shared HttpClient cache dependencies.

Initialize the scoped client

Initialize() must run before any request:

using Soenneker.Blazor.ApiClient.Abstract;

public sealed class WeatherApi
{
    private readonly IApiClient _api;

    public WeatherApi(IApiClient api, IConfiguration configuration)
    {
        _api = api;
        _api.Initialize(
            configuration["Api:BaseUrl"]!,
            requestResponseLogging: false);
    }
}

The base address must be absolute and HTTPS. Plain HTTP is accepted only for loopback development addresses.

Authenticated JSON request

public async Task<WeatherForecast?> GetForecast(
    CancellationToken cancellationToken)
{
    using HttpResponseMessage response = await _api.Get(
        "weather/forecast",
        cancellationToken: cancellationToken);

    response.EnsureSuccessStatusCode();
    return await response.Content.ReadFromJsonAsync<WeatherForecast>(
        cancellationToken);
}

Authenticated wrapper methods request the current access token from ISessionUtil and attach it as a bearer header to that request. Token headers are reused only while the token string remains unchanged.

Use allowAnonymous: true for a public endpoint:

using HttpResponseMessage response = await _api.Get(
    "health",
    allowAnonymous: true,
    cancellationToken: cancellationToken);

Authenticated requests cannot use an absolute URL on a different scheme, host, or port than the configured base address. This prevents forwarding a session token to another origin. Anonymous requests may use absolute URLs.

Request options

using Soenneker.Blazor.ApiClient.Dtos;

using HttpResponseMessage response = await _api.Post(
    new RequestOptions
    {
        Uri = "orders",
        Object = new { productId, quantity = 1 },
        LogRequest = true,
        LogResponse = false
    },
    cancellationToken);

LogRequest and LogResponse take effect only when requestResponseLogging was enabled during initialization. Logging may expose request or response data in the browser console; keep it disabled for sensitive production traffic.

File upload

await using FileStream stream = File.OpenRead(path);

using HttpResponseMessage response = await _api.Upload(
    new RequestUploadOptions
    {
        Uri = "documents",
        Stream = stream,
        FileName = Path.GetFileName(path),
        Object = new { category = "invoice" },
        LogRequest = true
    },
    cancellationToken);

Uploads are always authenticated. The multipart names are file for the binary stream and json for optional serialized metadata. The upload disposes its multipart content, which also disposes the supplied stream; do not reuse it afterward.

All methods return the raw HttpResponseMessage. The caller owns that response and is responsible for disposal, status handling, and response deserialization. GetClient() returns the cached transport client but does not attach authorization automatically; prefer the wrapper methods for authenticated calls.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Soenneker.Blazor.ApiClient:

Package Downloads
Soenneker.Blazor.Consumer.Base

An abstract wrapper around Soenneker.Blazor.ApiClient supporting auto (de)serialization for requests/responses/ProblemDetails.

Soenneker.Blazor.Consumers.Core

A class that represents the core Blazor Consumer, providing no additional functionality than access to Soenneker.Blazor.ApiClient

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.3306 390 11/3/2026
11.0.3305 117 11/3/2026
11.0.3304 116 11/3/2026
11.0.3303 129 11/3/2026
11.0.3301 143 11/3/2026
11.0.3300 141 11/3/2026
11.0.3299 79 11/3/2026
11.0.3298 86 11/3/2026
11.0.3297 114 11/3/2026
11.0.3296 81 11/3/2026
11.0.3295 151 11/3/2026
11.0.3293 122 11/3/2026
11.0.3290 194 11/2/2026
11.0.3289 184 11/2/2026
11.0.3288 171 11/2/2026
11.0.3287 397 10/29/2026
11.0.3286 444 10/27/2026
11.0.3285 142 10/27/2026
11.0.3284 106 10/26/2026
11.0.3283 117 10/26/2026
Loading failed

Update dependency Soenneker.Blazor.LogJson to 11.0.1948 (#3782)