JSolutionss.API.JSSHttpClient
1.1.12
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
<PackageReference Include="JSolutionss.API.JSSHttpClient" Version="1.1.12" />
<PackageVersion Include="JSolutionss.API.JSSHttpClient" Version="1.1.12" />
<PackageReference Include="JSolutionss.API.JSSHttpClient" />
paket add JSolutionss.API.JSSHttpClient --version 1.1.12
#r "nuget: JSolutionss.API.JSSHttpClient, 1.1.12"
#:package JSolutionss.API.JSSHttpClient@1.1.12
#addin nuget:?package=JSolutionss.API.JSSHttpClient&version=1.1.12
#tool nuget:?package=JSolutionss.API.JSSHttpClient&version=1.1.12
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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Net.Http.Headers (>= 2.2.0)
- Newtonsoft.Json (>= 13.0.1)
- Polly (>= 8.6.2)
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 |