Skip to content

mohsenTalal/-DotNet.RestApi.Client

Repository files navigation

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

Nuget Package:

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

Example of using with IHttpClientFactory ASP.NET Core

how to implement is coming later.

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>();

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 Web Service should have:

 public void ConfigureServices(IServiceCollection services)
 {
 ...
     services.AddResponseCompression();
 ...
 }
 public void Configure(IApplicationBuilder app)
 {
 ...
     app.UseResponseCompression();
 ...
 }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages