Soenneker.Blazor.ApiClient 4.0.3090

Prefix Reserved
dotnet add package Soenneker.Blazor.ApiClient --version 4.0.3090
                    
NuGet\Install-Package Soenneker.Blazor.ApiClient -Version 4.0.3090
                    
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="4.0.3090" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.ApiClient" Version="4.0.3090" />
                    
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 4.0.3090
                    
#r "nuget: Soenneker.Blazor.ApiClient, 4.0.3090"
                    
#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@4.0.3090
                    
#: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=4.0.3090
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.ApiClient&version=4.0.3090
                    
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 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 (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
4.0.3090 0 8/30/2026
4.0.3088 0 8/29/2026
4.0.3085 0 8/29/2026
4.0.3084 0 8/29/2026
4.0.3083 0 8/29/2026
4.0.3082 100 8/26/2026
4.0.3081 121 8/26/2026
4.0.3079 62 8/26/2026
4.0.3078 115 8/26/2026
4.0.3077 98 8/26/2026
4.0.3076 82 8/25/2026
4.0.3075 69 8/25/2026
4.0.3074 191 8/22/2026
4.0.3073 113 8/22/2026
4.0.3072 162 8/22/2026
4.0.3070 81 8/21/2026
4.0.3069 90 8/21/2026
4.0.3068 83 8/21/2026
4.0.3067 234 8/21/2026
4.0.3066 476 8/19/2026
Loading failed

Update dependency Soenneker.Extensions.Object to 4.0.4305 (#3576)