![]() |
VOOZH | about |
dotnet add package devdeer.Libraries.RestClient --version 11.0.10
NuGet\Install-Package devdeer.Libraries.RestClient -Version 11.0.10
<PackageReference Include="devdeer.Libraries.RestClient" Version="11.0.10" />
<PackageVersion Include="devdeer.Libraries.RestClient" Version="11.0.10" />Directory.Packages.props
<PackageReference Include="devdeer.Libraries.RestClient" />Project file
paket add devdeer.Libraries.RestClient --version 11.0.10
#r "nuget: devdeer.Libraries.RestClient, 11.0.10"
#:package devdeer.Libraries.RestClient@11.0.10
#addin nuget:?package=devdeer.Libraries.RestClient&version=11.0.10Install as a Cake Addin
#tool nuget:?package=devdeer.Libraries.RestClient&version=11.0.10Install as a Cake Tool
If you want to use this package you should be aware of some principles and practices we at DEVDEER use. So be aware that this is not backed by a public repository. The purpose here is to give out customers easy access to our logic. Nevertheless you are welcome to use this lib if it provides any advantages.
This package provides a simple JSON REST client which is based on the HttpClient class. It is designed to be used in a .NET Core environment. The main purpose of this lib is to provide a simple way
to call REST APIs and to handle the responses in a simple way. The lib is designed to be used in a dependency injection context.
In order to use the functionallity install the nuget package into your project. The you need to create a new type which inherits from JsonRestClient as follows:
public class MyRestClient : JsonRestClient
{
public MyJsonClient(HttpClient httpClient) : base(httpClient)
{
}
}
The above example shows only the simples of 9 available constructor overloads. You need to pick only one of them in order to devide which DI (dependency injection) you want to use.
If you want to use your REST client conveniently you usually add it to your DI:
services.AddHttpClient<MyJsonClient>(
(sp, client) =>
{
var config = sp.GetRequiredService<IConfiguration>();
client.BaseAddress = new Uri($"https://{config["OtherApi:Hostname"]}");
client.DefaultRequestHeaders.Add("Accept", "application/json");
// add more initialization if needed
});
In the example shown you would have some value in your appsettings.json like:
{
"OtherApi": {
"Hostname": "other.api.com"
}
}
Now lets say you have some component which needs to make JSON-REST-requests. You could do it like this:
public class MyComponent
{
private MyJsonClient _client;
public MyComponent(MyJsonClient client)
{
_client = client;
}
public async ValueTask<string> GetSomeDataAsync()
{
return await _client.GetAsync<string>("The/Relative/Endpoint");
}
public async ValueTask<SomeDataType> GetSomeDataAsync()
{
return await _client.GetAsync<SomeDataType>("Other/Relative/Endpoint");
}
}
There are other constructor overloads which allow you to pass the client configuration as well. Here is one example using the default options-injection:
public class MyRestClient : JsonRestClient
{
public MyJsonClient(HttpClient httpClient, IOptionsSnapshot<JsonRestClientOptions> options) : base(httpClient, options)
{
}
}
In order for this to work you need to register the options in your startup-DI. This examples uses the helper method from devdeer.Libraries.Abstractions which is a transient Nuget package that you get with this one automatically:
using devdeer.Libraries.Abstractions.Extensions;
services.RegisterOption<JsonRestClientOptions>("MyRestClient");
and the appsettings.json:
{
"OtherApi": {
"Hostname": "other.api.com"
},
"MyRestClient": {
"Resiliency": {
"UseRetryPolicy": true,
"RetryTimeoutBase": 1,
"RetryCount": 5
}
}
This assumes that you only need 1 JsonRestClient in your project and so you can use the default JsonRestClientOptions.
If you however need to have several implementations of JsonRestClient in your project you need to do a little more work.
Lets say you want to have 2 clients like this:
public class MyRestClient1 : JsonRestClient
{
public MyJsonClient(HttpClient httpClient, IOptionsSnapshot<JsonRestClientOptions> options) : base(httpClient, options)
{
}
}
public class MyRestClient2 : JsonRestClient
{
public MyJsonClient(HttpClient httpClient, IOptionsSnapshot<JsonRestClientOptions> options) : base(httpClient, options)
{
}
}
This would work but both clients would then share the same JsonRestClientOptions instance. So lets create 2 new types:
public class JsonRestClientOptions1 : JsonRestClientOptions
{
}
public class JsonRestClientOptions2 : JsonRestClientOptions
{
}
Change your app settings now:
{
"OtherApi": {
"Hostname": "other.api.com"
},
"RestClients": {
"1": {
"Resiliency": {
"UseRetryPolicy": true,
"RetryTimeoutBase": 1,
"RetryCount": 5
}
},
"2": {
},
}
The first client should use resiliency and the other should not. Now change your startup:
using devdeer.Libraries.Abstractions.Extensions;
services.RegisterOption<JsonRestClientOptions1>("RestClients:1");
services.RegisterOption<JsonRestClientOptions2>("RestClients:2");
Finally change the constructors of your types:
public class MyRestClient1 : JsonRestClient
{
public MyJsonClient(HttpClient httpClient, IOptionsSnapshot<JsonRestClientOptions1> options) : base(httpClient, options)
{
}
}
public class MyRestClient2 : JsonRestClient
{
public MyJsonClient(HttpClient httpClient, IOptionsSnapshot<JsonRestClientOptions2> options) : base(httpClient, options)
{
}
}
There are now several ways to use the client functionallity. The easiest way is to use wrapper functions like GetAsync<T> and PostAsync<T> as shown above.
One peculiar thing about our package are the *Oneway* functions which are there for you if just want to send a request to an endpoint and don't expect any result.
Also we provide a lot of overloads on the methods. In principal here are the ways to call our methods:
string.HttpContent.HttpRequestMessage directly.This scheme applies to all wrappers and direct Invoke* methods.
On excemption are the PerformDynamicRequestAsync overloads. This can be used like this:
var genericTemp = await _client.PerformDynamicRequestAsync($"path", HttpMethod.Get);
if (result == null)
{
// Whatever
}
return result["jsonRoute"].GetProperty("someProp").GetDouble();
In other words: the dynamic methods will return a dynamic type and allow you to call an API without need to map the data to .NET types. Be aware that this has performance implications and should be avoided normally.
This package uses Polly and Microsoft.Extensions.Resilience to incorporate resiliency optionally.
A documentation of this is upcoming...
DEVDEER is a company from Magdeburg, Germany which is specialized in consulting, project management and development. We are very focussed on Microsoft Azure as a platform to run our products and solutions in the cloud. So all of our backend components usually runs in this environment and is developed using .NET. In the frontend area we are using react and a huge bunch of packages to build our UIs.
You can find us online:
👁 YouTube
👁 YouTube Channel Subscribers
👁 YouTube Channel Views
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.10 | 228 | 5/15/2026 |
| 11.0.9 | 120 | 5/11/2026 |
| 11.0.8 | 189 | 5/4/2026 |
| 11.0.7 | 100 | 5/4/2026 |
| 11.0.6 | 163 | 4/19/2026 |
| 11.0.5 | 158 | 4/5/2026 |
| 11.0.4 | 157 | 3/22/2026 |
| 11.0.3 | 199 | 3/6/2026 |
| 11.0.2 | 244 | 1/14/2026 |
| 11.0.1 | 247 | 12/20/2025 |
| 11.0.0 | 188 | 12/13/2025 |
| 10.2.1 | 331 | 11/28/2025 |
| 10.2.0 | 497 | 11/20/2025 |
| 10.1.3 | 211 | 11/7/2025 |
| 10.1.2 | 296 | 10/21/2025 |
| 10.1.0 | 234 | 10/21/2025 |
| 10.0.2 | 219 | 10/18/2025 |
| 10.0.1 | 190 | 10/18/2025 |
| 9.0.8 | 379 | 10/15/2025 |
| 9.0.7 | 202 | 10/11/2025 |
- Fixed minor logging issues.
- Package updates.