Giter Club home page Giter Club logo

rest.service's Introduction

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
  }
}

rest.service's People

Contributors

rezaamd avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

nccmoi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.