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
<PackageReference Include="Soenneker.Blazor.ApiClient" Version="4.0.3090" />
<PackageVersion Include="Soenneker.Blazor.ApiClient" Version="4.0.3090" />
<PackageReference Include="Soenneker.Blazor.ApiClient" />
paket add Soenneker.Blazor.ApiClient --version 4.0.3090
#r "nuget: Soenneker.Blazor.ApiClient, 4.0.3090"
#:package Soenneker.Blazor.ApiClient@4.0.3090
#addin nuget:?package=Soenneker.Blazor.ApiClient&version=4.0.3090
#tool nuget:?package=Soenneker.Blazor.ApiClient&version=4.0.3090
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 | Versions 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. |
-
net10.0
- Soenneker.Blazor.LogJson (>= 4.0.1878)
- Soenneker.Blazor.Utils.Session (>= 4.0.2694)
- Soenneker.Extensions.Object (>= 4.0.4305)
- Soenneker.Utils.HttpClientCache (>= 4.0.2031)
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 |
Update dependency Soenneker.Extensions.Object to 4.0.4305 (#3576)