MSHelper.HTTP 1.0.0

dotnet add package MSHelper.HTTP --version 1.0.0
NuGet\Install-Package MSHelper.HTTP -Version 1.0.0
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="MSHelper.HTTP" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSHelper.HTTP --version 1.0.0
#r "nuget: MSHelper.HTTP, 1.0.0"
#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.
// Install MSHelper.HTTP as a Cake Addin
#addin nuget:?package=MSHelper.HTTP&version=1.0.0

// Install MSHelper.HTTP as a Cake Tool
#tool nuget:?package=MSHelper.HTTP&version=1.0.0

MSHelper.HTTP : HTTP

⭐ Star us on GitHub � it motivates us a lot!

Overview

Requests, service discovery, load balancing. Enhances the built-in HttpClient with an IHttpClient interface with retry policy using Polly and adds a possibility to easily use Consul service discovery and Fabio load balancing mechanisms, as well as switching between the different implementations.

Installation

This document is for the latest MSHelper.HTTP 1.0.0 release and later.

dotnet add package MSHelper.HTTP

Dependencies

-- MSHelper

Usage

Extend IMSHelperBuilder with AddHttpClient() that will register the required services.

public static IMSHelperBuilder RegisterMSHelper(this IMSHelperBuilder builder)
{
    builder.AddHttpClient();
    // Other services.
    
    return builder;
}

Then, simply inject IHttpClient (and optionally HttpClientOptions to resolve services URLS) to execute HTTP requests.

public class SomeService
{
    private readonly string _webService1Url;
    private readonly IHttpClient _client;

    public SomeService(IHttpClient _client, HttpClientOptions options)
    {
        _client = _client;
        _webService1Url = options.Services["web-service1"];
    }

    public async Task FooAsync()
    {
        var dto = await _client.GetAsync<Dto>($"{_webService1Url}/data");
    }
}

Usage

--- type - sets the IHttpClient message handler, if none is specified then the default handler will be used, other possible values: consul, fabio. --- retries - number of HTTP request retries using an exponential backoff. --- services - dictionary (map) of service_name:service_url values that can be used to invoke the other web services without a need to hardcode the configuration URLs, especially useful when service discovery mechanism or load balancer is available.

appsettings.json

"httpClient": {
  "type": "",
  "retries": 2,
  "services": {
    "web-service1": "http://localhost:5050",
    "web-service2": "web-service2-from-dns"
  }
}

Important Note:

All the MSHelper packages are for self learning purposes inspired by Devmentors.io

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on MSHelper.HTTP:

Package Downloads
MSHelper.Discovery.Consul

MSHelper.Discovery.Consul - Service Discovery

MSHelper.LoadBalancing.Fabio

MSHelper.LoadBalancing.Fabio - integrates with Fabio load balancer

MSHelper.HTTP.RestEase

MSHelper.HTTP.RestEase - RestEase Integration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 276 10/25/2022