Soenneker.X.Client
11.0.341
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.X.Client --version 11.0.341
NuGet\Install-Package Soenneker.X.Client -Version 11.0.341
<PackageReference Include="Soenneker.X.Client" Version="11.0.341" />
<PackageVersion Include="Soenneker.X.Client" Version="11.0.341" />
<PackageReference Include="Soenneker.X.Client" />
paket add Soenneker.X.Client --version 11.0.341
#r "nuget: Soenneker.X.Client, 11.0.341"
#:package Soenneker.X.Client@11.0.341
#addin nuget:?package=Soenneker.X.Client&version=11.0.341
#tool nuget:?package=Soenneker.X.Client&version=11.0.341
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 | net11.0 is compatible. |
-
net11.0
- Soenneker.Extensions.Configuration (>= 11.0.914)
- Soenneker.Utils.HttpClientCache (>= 11.0.2141)
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 |
|---|---|---|
| 11.0.350 | 75 | 11/11/2026 |
| 11.0.349 | 86 | 11/11/2026 |
| 11.0.348 | 76 | 11/11/2026 |
| 11.0.347 | 77 | 11/11/2026 |
| 11.0.346 | 67 | 11/11/2026 |
| 11.0.345 | 80 | 11/11/2026 |
| 11.0.344 | 77 | 11/11/2026 |
| 11.0.343 | 485 | 11/3/2026 |
| 11.0.342 | 119 | 11/3/2026 |
| 11.0.341 | 110 | 11/3/2026 |
| 11.0.340 | 123 | 11/3/2026 |
| 11.0.339 | 377 | 10/27/2026 |
| 11.0.338 | 135 | 10/27/2026 |
| 11.0.337 | 135 | 10/26/2026 |
| 11.0.336 | 95 | 10/26/2026 |
| 11.0.335 | 100 | 10/26/2026 |
| 4.0.334 | 577 | 10/15/2026 |
| 4.0.333 | 96 | 10/15/2026 |
| 4.0.332 | 116 | 10/14/2026 |
| 4.0.331 | 115 | 10/14/2026 |
Updated Multiple NuGet packages