SG.RestClient 1.0.0

C# Rest client to perform REST communication

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

SG.RestClient

C# Rest Client to perform REST communication in your .Net Apps

Import Reference

using SG.RestClient.Constant;
using SG.RestClient.Interface;
using SG.RestClient.Model;

RestClient Config:

RestConfig RestCfg = new RestConfig();
RestCfg.EnableLogOutput = true;
RestCfg.ProxySetting = Proxy.SystemDefault;

Description:

  1. EnableLogOutput : Provide log output when REST communication completed.
  2. ProxySetting : An indicator to determine proxy setting for your REST communication (SystemDefault, Custom, Disabled)
  3. Proxy : Define your proxy address here if you use custom proxy.
  4. BaseAddress : Base URL for your REST Service.

HttpConfig

HttpConfig config = new HttpConfig();
config.ContentType = MediaType.Json;
config.Method = HttpMethod.GET;
config.Headers = Headers;

Description:

  1. Method : POST, GET, etc
  2. ContentType : application/json, etc
  3. Headers : Custom headers
  4. TimeOut : Request timeout

Example :

RestClient RestClient = new RestClient(RestCfg);

GET

IRestClientResponse Result = await RestClient.GetAsync("http://localhost:88/RESTService/api/student", config);
IRestClientResponse Result = RestClient.GetAsync("http://localhost:88/RESTService/api/student", config).GetAwaiter().GetResult();

Result

bool IsSuccess = Result.Success;
string StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

LogOutput will be returned if RestConfig (EnableLogOutput) set to true

GET (with Return Type)

IRestClientResponse<Student> Result = await RestClient.GetAsync<Student>("http://localhost:88/RESTService/api/student", config)
IRestClientResponse<Student> Result = RestClient.GetAsync<Student>("http://localhost:88/RESTService/api/student", config).GetAwaiter().GetResult();

Result

bool IsSuccess = Result.Success;
Student StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

POST

There are 4 method that provided for verb-type POST:

Task<IRestClientResponse<TResult>> PostAsync<TResult, TRequest>(string Path, TRequest Request, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • Object Request (TRequest)
  • HttpConfig
Output
  • Object Response (TResult)

Task<IRestClientResponse<TResult>> PostAsync<TResult>(string Path, string StrJsonRequest, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • String Request
  • HttpConfig
Output
  • Object Response (TResult)

Task<IRestClientResponse> PostAsync<TRequest>(string Path, TRequest Request, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • Object Request (TRequest)
  • HttpConfig
Output
  • String Response

Task<IRestClientResponse> PostAsync(string Path, string StrJsonRequest, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • String Request
  • HttpConfig
Output
  • String Response

Example (POST)

POST Data

Student Student = new Student();
Student.StudentName = "Gunadi";
Student.StudentGrade = "IIA";
Student.StudentAddress = "Carl Street";
1
IRestClientResponse<Student> Result = await RestClient.PostAsync<Student>("http://localhost:88/RESTService/api/student", JsonConvert.SerializeObject(Student), config);
2
IRestClientResponse<Student> Result = await RestClient.PostAsync<Student, Student>("http://localhost:88/RESTService/api/student", Student, config);
3
IRestClientResponse Result = await RestClient.PostAsync<Student>("http://localhost:88/RESTService/api/student", Student, config)
4
IRestClientResponse Result = await RestClient.PostAsync("http://localhost:88/RESTService/api/student", JsonConvert.SerializeObject(Student), config);

Result

bool IsSuccess = Result.Success;
Student StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

SG.RestClient

C# Rest Client to perform REST communication in your .Net Apps

Import Reference

using SG.RestClient.Constant;
using SG.RestClient.Interface;
using SG.RestClient.Model;

RestClient Config:

RestConfig RestCfg = new RestConfig();
RestCfg.EnableLogOutput = true;
RestCfg.ProxySetting = Proxy.SystemDefault;

Description:

  1. EnableLogOutput : Provide log output when REST communication completed.
  2. ProxySetting : An indicator to determine proxy setting for your REST communication (SystemDefault, Custom, Disabled)
  3. Proxy : Define your proxy address here if you use custom proxy.
  4. BaseAddress : Base URL for your REST Service.

HttpConfig

HttpConfig config = new HttpConfig();
config.ContentType = MediaType.Json;
config.Method = HttpMethod.GET;
config.Headers = Headers;

Description:

  1. Method : POST, GET, etc
  2. ContentType : application/json, etc
  3. Headers : Custom headers
  4. TimeOut : Request timeout

Example :

RestClient RestClient = new RestClient(RestCfg);

GET

IRestClientResponse Result = await RestClient.GetAsync("http://localhost:88/RESTService/api/student", config);
IRestClientResponse Result = RestClient.GetAsync("http://localhost:88/RESTService/api/student", config).GetAwaiter().GetResult();

Result

bool IsSuccess = Result.Success;
string StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

LogOutput will be returned if RestConfig (EnableLogOutput) set to true

GET (with Return Type)

IRestClientResponse<Student> Result = await RestClient.GetAsync<Student>("http://localhost:88/RESTService/api/student", config)
IRestClientResponse<Student> Result = RestClient.GetAsync<Student>("http://localhost:88/RESTService/api/student", config).GetAwaiter().GetResult();

Result

bool IsSuccess = Result.Success;
Student StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

POST

There are 4 method that provided for verb-type POST:

Task<IRestClientResponse<TResult>> PostAsync<TResult, TRequest>(string Path, TRequest Request, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • Object Request (TRequest)
  • HttpConfig
Output
  • Object Response (TResult)

Task<IRestClientResponse<TResult>> PostAsync<TResult>(string Path, string StrJsonRequest, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • String Request
  • HttpConfig
Output
  • Object Response (TResult)

Task<IRestClientResponse> PostAsync<TRequest>(string Path, TRequest Request, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • Object Request (TRequest)
  • HttpConfig
Output
  • String Response

Task<IRestClientResponse> PostAsync(string Path, string StrJsonRequest, HttpConfig HttpConfig = null)
Input
  • URL/Path
  • String Request
  • HttpConfig
Output
  • String Response

Example (POST)

POST Data

Student Student = new Student();
Student.StudentName = "Gunadi";
Student.StudentGrade = "IIA";
Student.StudentAddress = "Carl Street";
1
IRestClientResponse<Student> Result = await RestClient.PostAsync<Student>("http://localhost:88/RESTService/api/student", JsonConvert.SerializeObject(Student), config);
2
IRestClientResponse<Student> Result = await RestClient.PostAsync<Student, Student>("http://localhost:88/RESTService/api/student", Student, config);
3
IRestClientResponse Result = await RestClient.PostAsync<Student>("http://localhost:88/RESTService/api/student", Student, config)
4
IRestClientResponse Result = await RestClient.PostAsync("http://localhost:88/RESTService/api/student", JsonConvert.SerializeObject(Student), config);

Result

bool IsSuccess = Result.Success;
Student StrResult = Result.Response;
string LogOutput = Result.LogOutput;
Exception Exception = Result.Exception;

Release Notes

Version 1.0.0

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 97 10/4/2019