DotNet.RestApi.Client 3.1.0

Dot NET Core REST API simple client.

Install-Package DotNet.RestApi.Client -Version 3.1.0
dotnet add package DotNet.RestApi.Client --version 3.1.0
<PackageReference Include="DotNet.RestApi.Client" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNet.RestApi.Client --version 3.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Dot Net Core Rest Web Api Client

The convenient Web Rest Api Client for the Rest Web Service at the Docker Container.

Version 3.1.0
  • Add support of .Net Core 3.1
  • Add support of .Net Standard 2.1
Version 3.0.0
  • Add support of .Net Core 3.0
  • Add support of .Net Standard 2.1
Version 2.4.0
  • Add support of IHttpClientFactory
  • Add support of IHttpClientFactory

Nuget Package:

https://www.nuget.org/packages/DotNet.RestApi.Client/

Development Supported by JetBrains Open Source Program:

Rider <a href="https://www.jetbrains.com/?from=XmlResult"> <img src="https://github.com/Wallsmedia/XmlResult/blob/master/Logo/rider/logo.png?raw=true" Width="40p" /></a> Fast & powerful,
cross platform .NET IDE

ReSharper <a href="https://www.jetbrains.com/?from=XmlResult"> <img src="https://github.com/Wallsmedia/XmlResult/blob/master/Logo/resharper/logo.png?raw=true" Width="40p" /></a> The Visual Studio Extension for .NET Developers

Example of using with IHttpClientFactory ASP.NET Core

Add to the configuration initialization:

.ConfigureServices((webHostBuilderContext, services) =>
  {
        services.AddHttpClient<RestApiClient>();
   })
Using "Polly"
.ConfigureServices((webHostBuilderContext, services) =>
  {
        services.AddTransient<RestApiClient>();
        services.AddHttpClient<RestApiClient>().AddTransientHttpErrorPolicy(p => p.RetryAsync(3));
   })

For more details of using Polly use link below:

  • https://github.com/App-vNext/Polly
  • http://www.thepollyproject.org

In the controller:

    private RestApiClient _restApiClient;

    /// <summary>
    /// Constructs the class.
    /// </summary>
    /// <param name="configuration">The capture processor configuration.</param>
    /// <param name="logFactory">The logger factory.</param>
    public MarketCaptureController(RestApiClient restApiClient,
        MarketCaptureProcessorServiceConfiguration configuration,
        ILoggerFactory logFactory)
    {
        _restApiClient = restApiClient;
        restApiClient.ConfigureHttpRequstMessage = RestApiClientExtensions.ApplyAcceptEncodingSettingGZip;

        Configuration = configuration;
        _logFactory = logFactory;
        _logInfo = _logFactory?.CreateLogger(Assembly.GetExecutingAssembly().GetName().Name);

    }

    private void GetBitCoinRate(object state)
    {

        try
        {
            Uri baseUri = new Uri(Configuration.BitCoinRequestUrl);
            baseUri = new Uri("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR");
            var response = _restApiClient.SendJsonRequest(HttpMethod.Get, baseUri, null).GetAwaiter().GetResult();
            var bitcoin = response.DeseriaseJsonResponseAsync<TickerBitcoin[]>().GetAwaiter().GetResult();
            LastMarketTop = bitcoin[0];
            LogMessageResources.TraceBitCoinPrice(_logInfo, bitcoin[0].LastUpdatedUTC, bitcoin[0].price_eur, null);
        }
        catch (Exception e)
        {
            LogMessageResources.OperationException(_logInfo, nameof(MarketCaptureProcessor), e);
        }
    }

Example how to call with JSON:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri);

PurchaseOrder sendObj = new PurchaseOrder();

HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, new Uri("res", UriKind.Relative), sendObj).Result;

PurchaseOrder respObj = response.DeseriaseJsonResponse<PurchaseOrder>();

Example how to call with XML:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri, request =>
   {
      request.Headers.Add("CustomHeader", "CustomHeaderValue");
   });

PurchaseOrder sendObj = new PurchaseOrder();

Uri relUri = new Uri(RequestPathAttribute.GetRestApiPath(sendObj), UriKind.Relative);
HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, relUri, sendObj).Result;

PurchaseOrder respObj = response.DeseriaseXmlResponse<PurchaseOrder>();

Example how to call with using gzip:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri, request =>
   {
      request.Headers.Add("CustomHeader", "CustomHeaderValue");
      RestApiClientExtensions.ApplyAcceptEncodingSettingGZip(request);
   });

PurchaseOrder sendObj = new PurchaseOrder();

HttpResponseMessage response = client.SendXmlRequest(HttpMethod.Post, new Uri("res", UriKind.Relative), sendObj).Result;

PurchaseOrder respObj = response.DeseriaseXmlResponse<PurchaseOrder>();

Where Web Service should have:
 public void ConfigureServices(IServiceCollection services)
 {
 ...
     services.AddResponseCompression();
 ...
 }
 public void Configure(IApplicationBuilder app)
 {
 ...
     app.UseResponseCompression();
 ...
 }

Example how to call with Data Contract XML:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri);

PurchaseOrder sendObj = new PurchaseOrder();
Uri relUri = new Uri(RequestPathAttribute.GetRestApiPath(sendObj), UriKind.Relative);
HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, relUri, sendObj).Result;

PurchaseOrder respObj = response.DeseriaseDcXmlResponse<PurchaseOrder>();

Where the Models:
   [DataContract (Namespace ="http://purchase.Interface.org/Purchase.Order")]
   [RequestPath("add/purchase/order")]
   public class PurchaseOrder
    {
        public PurchaseOrder()
        {
            billTo = new Address() { street = "Bill to Address" };
            shipTo = new Address() { street = "Ship to  Address" };
        }
        [DataMember]
        public Address billTo;
        [DataMember]
        public Address shipTo;
    }


    [DataContract(Namespace = "http://purchase.Interface.org/Purchase.Order.Address")]
    public class Address
    {
        [DataMember]
        public string street;
    }

Dot Net Core Rest Web Api Client

The convenient Web Rest Api Client for the Rest Web Service at the Docker Container.

Version 3.1.0
  • Add support of .Net Core 3.1
  • Add support of .Net Standard 2.1
Version 3.0.0
  • Add support of .Net Core 3.0
  • Add support of .Net Standard 2.1
Version 2.4.0
  • Add support of IHttpClientFactory
  • Add support of IHttpClientFactory

Nuget Package:

https://www.nuget.org/packages/DotNet.RestApi.Client/

Development Supported by JetBrains Open Source Program:

Rider <a href="https://www.jetbrains.com/?from=XmlResult"> <img src="https://github.com/Wallsmedia/XmlResult/blob/master/Logo/rider/logo.png?raw=true" Width="40p" /></a> Fast & powerful,
cross platform .NET IDE

ReSharper <a href="https://www.jetbrains.com/?from=XmlResult"> <img src="https://github.com/Wallsmedia/XmlResult/blob/master/Logo/resharper/logo.png?raw=true" Width="40p" /></a> The Visual Studio Extension for .NET Developers

Example of using with IHttpClientFactory ASP.NET Core

Add to the configuration initialization:

.ConfigureServices((webHostBuilderContext, services) =>
  {
        services.AddHttpClient<RestApiClient>();
   })
Using "Polly"
.ConfigureServices((webHostBuilderContext, services) =>
  {
        services.AddTransient<RestApiClient>();
        services.AddHttpClient<RestApiClient>().AddTransientHttpErrorPolicy(p => p.RetryAsync(3));
   })

For more details of using Polly use link below:

  • https://github.com/App-vNext/Polly
  • http://www.thepollyproject.org

In the controller:

    private RestApiClient _restApiClient;

    /// <summary>
    /// Constructs the class.
    /// </summary>
    /// <param name="configuration">The capture processor configuration.</param>
    /// <param name="logFactory">The logger factory.</param>
    public MarketCaptureController(RestApiClient restApiClient,
        MarketCaptureProcessorServiceConfiguration configuration,
        ILoggerFactory logFactory)
    {
        _restApiClient = restApiClient;
        restApiClient.ConfigureHttpRequstMessage = RestApiClientExtensions.ApplyAcceptEncodingSettingGZip;

        Configuration = configuration;
        _logFactory = logFactory;
        _logInfo = _logFactory?.CreateLogger(Assembly.GetExecutingAssembly().GetName().Name);

    }

    private void GetBitCoinRate(object state)
    {

        try
        {
            Uri baseUri = new Uri(Configuration.BitCoinRequestUrl);
            baseUri = new Uri("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR");
            var response = _restApiClient.SendJsonRequest(HttpMethod.Get, baseUri, null).GetAwaiter().GetResult();
            var bitcoin = response.DeseriaseJsonResponseAsync<TickerBitcoin[]>().GetAwaiter().GetResult();
            LastMarketTop = bitcoin[0];
            LogMessageResources.TraceBitCoinPrice(_logInfo, bitcoin[0].LastUpdatedUTC, bitcoin[0].price_eur, null);
        }
        catch (Exception e)
        {
            LogMessageResources.OperationException(_logInfo, nameof(MarketCaptureProcessor), e);
        }
    }

Example how to call with JSON:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri);

PurchaseOrder sendObj = new PurchaseOrder();

HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, new Uri("res", UriKind.Relative), sendObj).Result;

PurchaseOrder respObj = response.DeseriaseJsonResponse<PurchaseOrder>();

Example how to call with XML:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri, request =>
   {
      request.Headers.Add("CustomHeader", "CustomHeaderValue");
   });

PurchaseOrder sendObj = new PurchaseOrder();

Uri relUri = new Uri(RequestPathAttribute.GetRestApiPath(sendObj), UriKind.Relative);
HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, relUri, sendObj).Result;

PurchaseOrder respObj = response.DeseriaseXmlResponse<PurchaseOrder>();

Example how to call with using gzip:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri, request =>
   {
      request.Headers.Add("CustomHeader", "CustomHeaderValue");
      RestApiClientExtensions.ApplyAcceptEncodingSettingGZip(request);
   });

PurchaseOrder sendObj = new PurchaseOrder();

HttpResponseMessage response = client.SendXmlRequest(HttpMethod.Post, new Uri("res", UriKind.Relative), sendObj).Result;

PurchaseOrder respObj = response.DeseriaseXmlResponse<PurchaseOrder>();

Where Web Service should have:
 public void ConfigureServices(IServiceCollection services)
 {
 ...
     services.AddResponseCompression();
 ...
 }
 public void Configure(IApplicationBuilder app)
 {
 ...
     app.UseResponseCompression();
 ...
 }

Example how to call with Data Contract XML:

Uri baseUri = new Uri("http://webServiceHost:15002");
RestApiClient client = new RestApiClient(baseUri);

PurchaseOrder sendObj = new PurchaseOrder();
Uri relUri = new Uri(RequestPathAttribute.GetRestApiPath(sendObj), UriKind.Relative);
HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, relUri, sendObj).Result;

PurchaseOrder respObj = response.DeseriaseDcXmlResponse<PurchaseOrder>();

Where the Models:
   [DataContract (Namespace ="http://purchase.Interface.org/Purchase.Order")]
   [RequestPath("add/purchase/order")]
   public class PurchaseOrder
    {
        public PurchaseOrder()
        {
            billTo = new Address() { street = "Bill to Address" };
            shipTo = new Address() { street = "Ship to  Address" };
        }
        [DataMember]
        public Address billTo;
        [DataMember]
        public Address shipTo;
    }


    [DataContract(Namespace = "http://purchase.Interface.org/Purchase.Order.Address")]
    public class Address
    {
        [DataMember]
        public string street;
    }

Release Notes

Singed assembly. Release: netstandard2.1;netcoreapp3.0;netcoreapp3.1; includes gzip response support; async extensions;

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.1.0 683 1/11/2020
3.0.0 203 10/17/2019
2.4.0 484 9/16/2018
2.3.1 534 6/5/2018
2.2.1 447 12/8/2017
2.2.0 344 11/9/2017
2.1.0 370 9/25/2017
2.0.2 352 9/23/2017
2.0.1 357 9/3/2017
2.0.0 371 8/28/2017
1.0.2 376 7/29/2017