Soenneker.X.Client 4.0.272

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.X.Client --version 4.0.272
                    
NuGet\Install-Package Soenneker.X.Client -Version 4.0.272
                    
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.X.Client" Version="4.0.272" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.X.Client" Version="4.0.272" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.X.Client" />
                    
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.X.Client --version 4.0.272
                    
#r "nuget: Soenneker.X.Client, 4.0.272"
                    
#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.X.Client@4.0.272
                    
#: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.X.Client&version=4.0.272
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.X.Client&version=4.0.272
                    
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

alternate text is missing from this package README image 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 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 (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.305 55 9/17/2026
4.0.304 45 9/16/2026
4.0.303 58 9/16/2026
4.0.302 43 9/16/2026
4.0.301 77 9/16/2026
4.0.300 77 9/15/2026
4.0.299 75 9/15/2026
4.0.298 145 9/13/2026
4.0.297 102 9/13/2026
4.0.296 92 9/13/2026
4.0.295 90 9/13/2026
4.0.294 104 9/12/2026
4.0.291 178 9/9/2026
4.0.290 134 9/9/2026
4.0.289 103 9/9/2026
4.0.288 126 9/8/2026
4.0.287 174 9/8/2026
4.0.286 117 9/8/2026
4.0.285 125 9/7/2026
4.0.272 96 8/31/2026
Loading failed

Updated NuGet packages