TheProcessE.RestClient 1.0.0

Suggested Alternatives

Refit

There is a newer version of this package available.
See the version list below for details.
dotnet add package TheProcessE.RestClient --version 1.0.0                
NuGet\Install-Package TheProcessE.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="TheProcessE.RestClient" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheProcessE.RestClient --version 1.0.0                
#r "nuget: TheProcessE.RestClient, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TheProcessE.RestClient as a Cake Addin
#addin nuget:?package=TheProcessE.RestClient&version=1.0.0

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

Rest-Client

A simple HttpClient for making http requests

Supported HTTP METHODS

  • GET
  • POST
  • PUT
  • DELETE

Supported HTTP request Data

  • BODY
  • HEADER/HEADERS

How To Use

1 - Create an Interface with your request methods

2 - Add a URL attribute to your interface with the base-url

3 - Mark the methods with correct HttpMethod using (GET, POST, PUT, DELETE)

4 - Mark the parameters as Header or BODY using the Header or BODY attribute

5 - Mark the return type of your method as a Task<Response> or Response

6 - Call the GetService method of the RestService class with your type as parameter

7 - All done !! you may now make http calls

Target FrameWork

.NETFramework4.7.2

Test Example getting the posts from json placeholder

Example of Service Interface

  [URL(@"https://jsonplaceholder.typicode.com")]
  public interface IExampleInterface
  {
      [GET("posts")]
      Task<Response> Posts();

      [GET("todos")]
      Response Todos();

      [GET("users")]
      Task<Response> Users();
  }

Example of post class

  class Post
  {
      public int UserId { get; set; }
      public int Id { get; set; }
      public string Title { get; set; }
      public string body { get; set; }
  }

Instantiating a new Service of your given type

  // Create a new RestService of type IExampleInterface
  var testService = RestService.GetService<IExampleInterface>();

Getting the posts

// if not using async mark the method return type as Response
// or use var response = testService.Posts().Result;
var response = await testService.Posts();
var posts = response.GetResponse<Post[]>();

Console.WriteLine($"First Post: {posts[0].Title}");
Console.Read();

Author

Pascal Nsunba

License

MIT LICENSE

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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.

First release.