HttpExtension 5.0.0

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

// Install HttpExtension as a Cake Tool
#tool nuget:?package=HttpExtension&version=5.0.0                

HttpExtension

Extensions for HttpClient

This is the component, works on .NET Core and.NET Framework

NuGet

Name Info Contributors
HttpExtension NuGet GitHub contributors

Platform Support

HttpExtension is a netstandard 2.1 library.

Extensions to make using HttpClient easy.

  • GetAsync<T> : Gets the return of a Get Rest and converts to the object or collection of pre-defined objects. You can use only the path of the rest method, or pass a parameter dictionary. In case the url has parameters.
 public static async Task<HttpExtensionResponse<T>> GetAsync<T>(this HttpClient httpClient, string address);
 public static async Task<HttpExtensionResponse<T>> GetAsync<T>(this HttpClient httpClient, string address, Dictionary<string, string> values);
  • PostAsync<T>,PutAsync<T> and DeleteAsync<T> : Use post, put and delete service methods rest asynchronously and return objects if necessary.
 public static async Task<HttpResponseMessage> PostAsync(this HttpClient httpClient, string address, object dto);
 public static async Task<HttpExtensionResponse<T>> PostAsync<T>(this HttpClient httpClient, string address, object dto);
 
 public static async Task<HttpResponseMessage> PutAsync(this HttpClient httpClient,string address, object dto);
 public static async Task<HttpExtensionResponse<T>> PutAsync<T>(this HttpClient httpClient, string address, object dto);
 
 public static async Task<HttpResponseMessage> DeleteAsync(this HttpClient httpClient,string address, object dto);
 public static async Task<HttpExtensionResponse<T>> DeleteAsync<T>(this HttpClient httpClient, string address, object dto);
  • SendAsync<T> : Use SendAsync for your custom HTTP request message and return predefined objects or collection.
 public static async Task<HttpExtensionResponse<T>> SendAsync<T>(this HttpClient httpClient, HttpRequestMessage request);
  • HttpExtensionResponse<T> : Object that facilitates the return of requests Rest. It returns the Http code of the request, already converted object and the contents in case of errors.
public class HttpExtensionResponse<T>
{
  public HttpStatusCode StatusCode { get; private set; }

  public T Value { get; set; }

  public string Content { get; set; }

  public Exception Error { get; set; }
}

Example of use :

public async Task<List<Model.Todo>> GetTodos()
{
    try
    {
        //GetAsync Return with Object
        var response = await _httpClient.GetAsync<List<Model.Todo>>("todos");
           
        if (response.StatusCode == HttpStatusCode.OK)
        {
              return response.Value;
        }
        else
        {
            throw new Exception(
                   $"HttpStatusCode: {response.StatusCode.ToString()} Message: {response.Content}");
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Retry Pattern support using Polly

You can use the retry pattern with HttpExtension using Polly.

Example of use :

public async Task<List<Model.Todo>> GetTodos()
{
    var policy = CreatePolicy();
    try
    {
        //GetAsync using retry pattern
        var response = await _httpClient.GetAsync<List<Model.Todo>>("todos", policy);
           
        if (response.StatusCode == HttpStatusCode.OK)
            return response.Value;
        else
        {
            throw new Exception(
                   $"HttpStatusCode: {response.StatusCode.ToString()} Message: {response.Content}");
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

private AsyncRetryPolicy CreatePolicy()
{
    return Policy
    .Handle<HttpRequestException>()
    .WaitAndRetryAsync(
        retryCount: 3,
        sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(2)
    );
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on HttpExtension:

Package Downloads
RepositoryHelpers

Extensions for HttpClient and Custom Repository based on dapper

Xamarin.Helpers

Extensions for HttpClient, Tasks and objects. Helpers to manipulate images

AppCenter.Helpers

Helpers to use app center APIs

Bertuzzi.MAUI.Helpers

Extensions for HttpClient, Tasks and objects. Helpers to manipulate images

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 4,117 4/18/2024
4.0.0 17,152 7/26/2022
3.1.2 426 7/26/2022
3.1.1 7,802 7/12/2021
3.0.0 1,201 6/13/2021
2.2.0 474 5/17/2021
2.1.0 42,376 7/20/2020
2.0.0 611 3/19/2020
1.2.0 6,284 9/10/2019
1.1.0 1,083 5/20/2019
1.0.0 949 2/21/2019

compatibility change to netstandard2.1 and package updates