HttpExtension 5.0.0
dotnet add package HttpExtension --version 5.0.0
NuGet\Install-Package HttpExtension -Version 5.0.0
<PackageReference Include="HttpExtension" Version="5.0.0" />
paket add HttpExtension --version 5.0.0
#r "nuget: HttpExtension, 5.0.0"
// 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 |
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 | Versions 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. |
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 7.2.3)
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.
compatibility change to netstandard2.1 and package updates