Pdsr.Http
3.7.1
See the version list below for details.
dotnet add package Pdsr.Http --version 3.7.1
NuGet\Install-Package Pdsr.Http -Version 3.7.1
<PackageReference Include="Pdsr.Http" Version="3.7.1" />
paket add Pdsr.Http --version 3.7.1
#r "nuget: Pdsr.Http, 3.7.1"
// Install Pdsr.Http as a Cake Addin #addin nuget:?package=Pdsr.Http&version=3.7.1 // Install Pdsr.Http as a Cake Tool #tool nuget:?package=Pdsr.Http&version=3.7.1
Pdsr HttpClient Helper
A helper library to use with HTTP API Calls
Getting Started
you need to install the package, add to DI and then use it in services.
- install the package
dotnet add package Pdsr.HttpClient
and for extensionsdotnet add package Pdsr.HttpClient.Extensions
. - Inject an
System.Net.HttpClient
to the DI container. - Implement the
IPdsrClientBase
or inherit the abstract classPdsrClientBase
and override any methods required.
public class SomeService
{
private readonly IPdsrClient _client;
public SomeService(IPdsrClient client) => _client = client;
public async Task SomeAsyncMethod(string someRouteId, string someQueryStringValue, CancellationToken cancellationToken = default)
{
var results = await _client.Url("https://example.com/api").AddUrl(someRouteId)
.AddQueryString ("key" , someQueryStringValue)
.Accept("application/vnd.api.custom+custom")
.OnBadRequest( (res)=>
{
// do something
})
.OnException( (ex) =>
{
// do something about the exception
})
.OnNoFound( (res) =>
{
// do something when resource not found.
})
// and any other status code and so on
// or add handler to the Client to run on certain situations
// or add handler to the HttpRequestMessage on certain situations
.Post(new { Something = "some value" })
.SnakeCase()
.SendAsync<SomeModelSupposeToDeserializeTo>(cancellationToken);
return results;
}
}
you need to override the abstract method GetAuthorizationHeader
if your API needs authentication and implement the authorization logic there.
protected abstract Task SetAuthorizationHeader(HttpRequestMessage request, CancellationToken cancellationToken = default);
You can also log all requests and responses in the inherited class, to have one code log all requests.
protected abstract Task WriteLog(HttpResponseMessage response, long ellapsed, CancellationToken cancellationToken = default);
Use the required Serializer/Deserializer Name casing.
Right now, it only supports CamelCase
by default and SnakeCase
can be used as well.
In case of deserialization, if your API does not return any model or you want to get anything else other than Model, such as Stream, String, or the HttpResponseMessage itself, you can use the respected method such as GetStream
or GetString
and override the SendAsync
to return the Message itself.
Contribute
Please refer to contribute.
Documents
Under Construction.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- Microsoft.AspNetCore.WebUtilities (>= 2.2.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Text.Json (>= 7.0.3)
-
.NETStandard 2.1
- Microsoft.AspNetCore.WebUtilities (>= 2.2.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Text.Json (>= 7.0.3)
-
net6.0
- Microsoft.AspNetCore.WebUtilities (>= 2.2.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Text.Json (>= 7.0.3)
-
net7.0
- Microsoft.AspNetCore.WebUtilities (>= 2.2.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Text.Json (>= 7.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pdsr.Http:
Package | Downloads |
---|---|
Pdsr.Http.Extensions
HttpClient Helper extensions |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.8.0-preview.2 | 151 | 10/9/2024 |
3.7.1 | 2,703 | 9/5/2023 |
3.7.0 | 354 | 7/19/2023 |
3.7.0-preview.1 | 1,795 | 4/27/2023 |
3.6.3 | 1,093 | 2/20/2023 |
3.6.2 | 406 | 2/20/2023 |
3.6.1 | 666 | 11/11/2022 |
3.6.0 | 578 | 11/11/2022 |
3.5.4 | 652 | 8/26/2022 |
3.5.3 | 663 | 8/26/2022 |
3.5.1.445 | 1,097 | 4/17/2022 |
3.5.0.443 | 711 | 4/17/2022 |
3.5.0.442 | 710 | 4/17/2022 |