IdentityServer4.Contrib.HttpClientService
2.1.0
See the version list below for details.
dotnet add package IdentityServer4.Contrib.HttpClientService --version 2.1.0
NuGet\Install-Package IdentityServer4.Contrib.HttpClientService -Version 2.1.0
<PackageReference Include="IdentityServer4.Contrib.HttpClientService" Version="2.1.0" />
<PackageVersion Include="IdentityServer4.Contrib.HttpClientService" Version="2.1.0" />
<PackageReference Include="IdentityServer4.Contrib.HttpClientService" />
paket add IdentityServer4.Contrib.HttpClientService --version 2.1.0
#r "nuget: IdentityServer4.Contrib.HttpClientService, 2.1.0"
#:package IdentityServer4.Contrib.HttpClientService@2.1.0
#addin nuget:?package=IdentityServer4.Contrib.HttpClientService&version=2.1.0
#tool nuget:?package=IdentityServer4.Contrib.HttpClientService&version=2.1.0
An HttpClient service for IdentityServer4
An HttpClient service that makes it easy to make authenticated HTTP requests to protected by IdentityServer4 resources. Complex types are automatically serialized for requests / deserialized form responses, all with a fluent interface design:
var responseObject = await _requestServiceFactory
//Create a instance of the service
.CreateHttpClientService()
//Also supports IOptions<>
.SetIdentityServerOptions("appsettings_section")
//GET and deserialize the response body to IEnumerable<Customers>
.GetAsync<IEnumerable<Customers>>("https://api/customers");
The variable responseObject contains multiple properties: from the entire HttpResponseMessage and HttpRequestMessage, to HttpStatusCode and HttpResponseHeaders. The most exciting feature though, is the TResponseBody BodyAsType property which will contain deserializabled complex types from JSON responses (in the example above the BodyAsType will be of type IEnumerable<Customers>). Check the ResponseObject<TResponseBody> in the docs.
Setting up complex request body for POST, PUT and PATCH requests is also very easy! Here are some examples:
var responseObject = await _requestServiceFactory
//Create a instance of the service
.CreateHttpClientService()
//.PostAsync<TRequestBody,TResponseBody>(URL, customer of type Customer1)
.PostAsync<Customer1,Customer2>("https://api/customers", customer);
You can also fine tune encoding and media-type by using the TypeContent(TRequestBody model, Encoding encoding, string mediaType) like this:
var responseObject = await _requestServiceFactory
//Create a instance of the service
.CreateHttpClientService()
//.PostAsync<TRequestBody,TResponseBody>(URL, customer of type Customer1)
.PostAsync<TypeContent<Customer1>,Customer2>("https://api/customers", new TypeContent(customer, Encoding.UTF8, "application/json"));
HTTP verbs supported are: GET, POST, PUT, DELETE, PATCH and HEAD. Read the Documentation for technical details, check the features sample or a more complete one.
Getting Started
Getting started with IdentityServer4.Contrib.HttpClientService is easy; you only need three things:
- Install the nuget package IdentityServer4.Contrib.HttpClientService
- Provide the options to authenticate in
appsettings.json - Register the service in
Startup.cs
Read the entire Getting Started guide for a quick start. You can also take a look at the Documentation, check the features sample or a more complete one.
Contributing
Feedback and contibution is more than welcome, as there are many more things to do!
Just as a sample:
- Expand the IdentityServer4.Contrib.HttpClientService.CompleteSample with more functionality.
- Support
JsonSerializerSettingsforJsonConvert.DeserializeObject<TResponseBody>(apiResponse.BodyAsString)in HttpClientService. - Support more than
ClientCredentials. - Add logging.
Many more are coming soon and all of them should be issues, so feel free to open one and let's start discussing solutions!
| 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. 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. |
| .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
- IdentityModel (>= 4.1.1)
- Microsoft.AspNet.WebApi.Client (>= 5.2.7)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Caching.Memory (>= 3.1.2)
- Microsoft.Extensions.Http (>= 3.1.2)
- Microsoft.Extensions.Options (>= 3.1.2)
- Newtonsoft.Json (>= 12.0.3)
- System.Configuration.ConfigurationManager (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.3.6 | 149,842 | 7/6/2021 | |
| 2.3.5 | 140,370 | 10/13/2020 | |
| 2.3.4 | 990 | 8/3/2020 | |
| 2.3.3 | 632 | 7/28/2020 | |
| 2.3.1 | 644 | 7/28/2020 | |
| 2.3.0 | 7,749 | 3/19/2020 | |
| 2.2.2 | 651 | 3/16/2020 | |
| 2.2.1 | 803 | 3/11/2020 | |
| 2.2.0 | 652 | 3/11/2020 | |
| 2.1.0 | 674 | 3/6/2020 | |
| 2.0.0 | 652 | 3/5/2020 | |
| 1.1.0 | 1,033 | 3/3/2020 | |
| 1.0.1 | 975 | 3/2/2020 | |
| 1.0.0 | 914 | 3/2/2020 | |
| 0.0.1-alpha | 1,057 | 3/2/2020 |