JSolutionss.API.JSSHttpClient 1.1.12

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

Acerca

Librería para encapsular llamadas HTTP a APIs REST usando HttpClientFactory, con soporte para:

GET / POST

✔ Body y headers dinámicos ✔ Token Bearer ✔ Timeout por request ✔ Reintentos controlados ✔ Manejo de errores estandarizado (JssApiException) ✔ Uso directo o vía Fluent Builder

Configuración básica

Configurar en Program.cs las siguientes lineas de codigo.

builder.Services.AddHttpClient();
builder.Services.AddSingleton<IHttpServiceFactory, HttpServiceFactory>();

Uso básico (sin reintentos)

Ejemplo de uso desde un servicio de aplicación:

public class ServiceSample : IServiceSample
{
    private readonly IHttpServiceFactory _httpServiceFactory;

    public ServiceSample(IHttpServiceFactory httpServiceFactory)
    {
        _httpServiceFactory = httpServiceFactory;
    }

    public async Task<IEnumerable<ItemModel>> GetAll(FilterModel filter)
    {
        return await _httpServiceFactory.SendAsync<IEnumerable<ItemModel>>(
            clientName: "default",
            method: HttpMethod.Post,
            relativeUrl: "api/items/get-all",
            body: filter,
            headers: null,
            token: null,
            timeoutSeconds: 15,
            retryCount: 0,              // sin reintentos
            retryDelay: TimeSpan.Zero,
            ct: CancellationToken.None
        );
    }
}

Uso con GET

var result = await _httpServiceFactory.SendAsync<List<ItemModel>>(
    clientName: "default",
    method: HttpMethod.Get,
    relativeUrl: "api/items?id=10&activo=true",
    body: null,
    headers: null,
    token: token,
    timeoutSeconds: 10,
    retryCount: 0,
    retryDelay: TimeSpan.Zero,
    ct: ct
);

Uso con reintentos (RESILIENCIA)

Los reintentos no son automáticos, se habilitan explícitamente.

var result = await _httpServiceFactory.SendAsync<MyResponseDto>(
    clientName: "ApiClientes",
    method: HttpMethod.Post,
    relativeUrl: "clientes",
    body: new ClienteRequest { Id = 10 },
    headers: null,
    token: "jwt-token-aqui",
    timeoutSeconds: 20,
    retryCount: 3,
    retryDelay: TimeSpan.FromMilliseconds(500),
    ct: CancellationToken.None
);

Uso con HttpClient nombrado

Configurar en Program.cs las siguientes lineas de codigo.

builder.Services.AddHttpClient("NamedHttpClient")
    .SetHandlerLifetime(TimeSpan.FromMinutes(5))
    .ConfigureHttpMessageHandlerBuilder(builder =>
    {
        builder.PrimaryHandler = new HttpClientHandler
        {
            ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
        };
    });

builder.Services.AddScoped<IHttpServiceFactory, HttpServiceFactory>();

Uso

var result = await _httpServiceFactory.SendAsync<MyResponseDto>(
    clientName: "NamedHttpClient",
    method: HttpMethod.Post,
    relativeUrl: "api/datos",
    body: new { id = 5 },
    headers: null,
    token: "jwt-token-aqui",
    timeoutSeconds: 15,
    retryCount: 2,
    retryDelay: TimeSpan.FromMilliseconds(300),
    ct: CancellationToken.None
);

Manejo de errores

Todos los errores HTTP y de infraestructura lanzan:

JssApiException

Incluye:

Nombre del cliente HTTP

URL

Método HTTP

StatusCode (si aplica)

Body de error (si existe)

Excepción original

try
{
    await service.CallApi();
}
catch (JssApiException ex)
{
    // logging centralizado
    // ex.ClientName
    // ex.Url
    // ex.Method
    // ex.StatusCode
    // ex.ResponseBody
}

Fluent Builder (opcional)

Para llamadas más expresivas:

var result = await http
    .Client("ApiClientes")
    .Post("clientes")
    .WithParams(new ClienteRequest { Id = 10 })
    .WithRetry(3, 500)
    .SendAsync<ClienteDto>();

Principios de diseño

El consumidor no crea HttpRequestMessage

La infraestructura maneja: ✔ construcción del request, ✔ reintentos, ✔ timeouts, ✔ errores, ✔ Código limpio, testeable y extensible

Principios de diseño

Reintentos solo en operaciones idempotentes ✔ No usar retry en POST no idempotentes ✔ Centralizar logging sobre JssApiException ✔ Preferir HttpClient nombrados para APIs externas

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 JSolutionss.API.JSSHttpClient:

Package Downloads
JSolutionss.API.MaestroProxy

Package Description

JSolutionss.Proxy.Roles

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.14 134 1/3/2026
1.1.13 130 1/3/2026
1.1.12 214 12/24/2025
1.1.11 205 12/23/2025
1.1.10 208 12/23/2025
1.1.9 193 7/31/2025
1.1.8 284 4/15/2025
1.1.7 460 8/25/2023
1.1.6 284 8/4/2023
1.1.5 262 8/4/2023
1.1.4 280 6/15/2023
1.1.3 305 5/15/2023
1.1.2 275 5/15/2023
1.1.1 458 12/16/2022
1.1.0 440 12/16/2022
1.0.0 493 9/9/2022