SG.RestClient 1.0.0

.NET Framework 4.6
dotnet add package SG.RestClient --version 1.0.0
NuGet\Install-Package SG.RestClient -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: SG.RestClient, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SG.RestClient as a Cake Addin
#addin nuget:?package=SG.RestClient&version=1.0.0

// Install SG.RestClient as a Cake Tool
#tool nuget:?package=SG.RestClient&version=1.0.0

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;

Product Versions
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 430 10/4/2019

Version 1.0.0