Skip to content

.net service mediator for RestSharp package for REST request, send body and authorization on config.

Notifications You must be signed in to change notification settings

oopsiwoopsi/Rest.Service

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rest.Service

NuGet

Dotnet service wrapper for RestSharp package for REST request.

How to use?

In .Net Core - NuGet:

Install-Package Rest.Service

Quick start

For example in c# console:

  using RestSharp.Service;
internal class Program
{
  private IRestService restService = new RestService();
  
  void Main(string[] args)
  {
    var response = restService.Request("https://google.com");
      
    Console.WriteLine(response.StatusCode);
  }
}

Configs

Default request is GET, also you can request on other actions (Post, Put, Delete, ...) e.g.

    var response = restService.Request("https://google.com", HttpMethod.Post, new()
    {
      Authorization = new RestBearerAuth("JWT_TOKEN"),
      Body = object,
      Headers = new Dictionary<string, string>(),
      Parameters = new Dictionary<string, string>()
    });

Supported authentications: RestBearerAuth("JWT_TOKEN") RestBasicAuth(username, password) RestHawkAuth(string authId, string authKey, HawkAlgorithm algorithm = HawkAlgorithm.Sha256)

How to use in Asp.net?

1- At first, we need config Rest.Service in startup.cs:

using RestSharp.Service;
Services.AddRestServices();

2- Now to use, do the following:

using RestSharp;
using RestSharp.Service.Interfaces;
public class HomeController : ControllerBase
{

  private readonly IRestService restService;
  
  public HomeController(IRestService _restService)
  {
    restService = _restService;
  }
  
  [HttpGet]
  public IActionResult Index()
  {
    var response = restService.Request("https://google.com"); // GET Request
  }
}

About

.net service mediator for RestSharp package for REST request, send body and authorization on config.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%