Soenneker.X.Client
4.0.284
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.X.Client --version 4.0.284
NuGet\Install-Package Soenneker.X.Client -Version 4.0.284
<PackageReference Include="Soenneker.X.Client" Version="4.0.284" />
<PackageVersion Include="Soenneker.X.Client" Version="4.0.284" />
<PackageReference Include="Soenneker.X.Client" />
paket add Soenneker.X.Client --version 4.0.284
#r "nuget: Soenneker.X.Client, 4.0.284"
#:package Soenneker.X.Client@4.0.284
#addin nuget:?package=Soenneker.X.Client&version=4.0.284
#tool nuget:?package=Soenneker.X.Client&version=4.0.284
Soenneker.X.Client
Provides a cached HttpClient configured for X API v2. Authentication is applied per request so the same transport can safely serve app-only and user-context calls.
Installation
dotnet add package Soenneker.X.Client
Registration and usage
using System.Net.Http.Headers;
using Soenneker.X.Client.Abstract;
using Soenneker.X.Client.Registrars;
services.AddXHttpClientAsSingleton();
public sealed class XUserService
{
private readonly IXHttpClient _clientProvider;
public XUserService(IXHttpClient clientProvider)
{
_clientProvider = clientProvider;
}
public async Task<string> GetByUsername(
string username,
string bearerToken,
CancellationToken cancellationToken)
{
HttpClient client = await _clientProvider.Get(cancellationToken);
using var request = new HttpRequestMessage(
HttpMethod.Get,
$"users/by/username/{Uri.EscapeDataString(username)}");
request.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", bearerToken);
using HttpResponseMessage response = await client.SendAsync(
request,
cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync(cancellationToken);
}
}
Do not place a per-user token in DefaultRequestHeaders on the shared client. Add the appropriate app bearer token or OAuth user access token to each request; X endpoints differ in which authentication context they accept.
Use AddXHttpClientAsScoped() when the provider should follow a scope. Each provider owns its cached client and removes it when disposed.
| 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.Extensions.Configuration (>= 4.0.878)
- Soenneker.Utils.HttpClientCache (>= 4.0.2062)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.X.Client:
| Package | Downloads |
|---|---|
|
Soenneker.X.ClientUtil
Provides a cached X OpenAPI client authenticated with a configured bearer token. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.294 | 0 | 9/12/2026 |
| 4.0.291 | 90 | 9/9/2026 |
| 4.0.290 | 97 | 9/9/2026 |
| 4.0.289 | 70 | 9/9/2026 |
| 4.0.288 | 89 | 9/8/2026 |
| 4.0.287 | 135 | 9/8/2026 |
| 4.0.286 | 99 | 9/8/2026 |
| 4.0.285 | 112 | 9/7/2026 |
| 4.0.284 | 115 | 9/7/2026 |
| 4.0.283 | 112 | 9/7/2026 |
| 4.0.282 | 196 | 9/5/2026 |
| 4.0.281 | 118 | 9/5/2026 |
| 4.0.280 | 114 | 9/4/2026 |
| 4.0.279 | 97 | 9/4/2026 |
| 4.0.278 | 131 | 9/4/2026 |
| 4.0.277 | 121 | 9/4/2026 |
| 4.0.275 | 113 | 9/4/2026 |
| 4.0.274 | 173 | 9/1/2026 |
| 4.0.273 | 94 | 8/31/2026 |
| 4.0.272 | 93 | 8/31/2026 |
Updated Multiple NuGet packages