Skip to content

developer82/Rest.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST.NET

Build status BuitlWithDot.Net shield

REST.NET is a simple REST and HTTP API Client for .NET Core. Why another REST client? When I started developing .NET core I couldn't find a suitable replacement for RestSharp library that suits my needs, so I decided to create one. It's basically a wrapper around HttpClient, which makes API calls much simpler and with fewer lines of code.

Note: I'm developing this library per my project needs on my free time. So not everything you expect might be here and I didn't have a chance to check everything up. You are welcome to help (even reporting known bugs or suggesting features by opening an issue is helpful).

Pro tip: Much can be learned from having a look at the Unit Tests project ;)


Installation

REST.NET is available via NuGet package:

Install-Package Rest.Net

Documentation

Creating RestClient

The first thing you will need to do is create a RestClient. This object is what's wrapping HttpClient and responsible for dispatching http requests. You can use the same object for multiple calls.

IRestClient client = new RestClient("http://www.yourapi.com/");

Making API requests

Most of the libraries I encountered (including the HttpClient object) requires you to first create a request object and pass that to the client - which for most use cases I found redundant and unnecessary. 90% of the time I found myself writing the same request object, so to simplify, REST.NET supports sending "simple" requests directly from the client object.

Synchronous requests examples

// GET requests
IRestResponse<string> result = client.Get("/person/123");
IRestResponse<Person> person = client.Get<Person>("/person/123");

// PUT requests
Person person = new Person()
{
    FirstName = "Ophir",
    LastName = "Oren"
};
IRestResponse<string> result = client.Put("/person", person);
IRestResponse<Person> person = client.Put<Person>("/person");

// POST requests
Person person = new Person()
{
    Id = 1,
    FirstName = "Ophir",
    LastName = "Oren"
};
IRestResponse<string> result = client.Post("/person", person);
IRestResponse<Person> person = client.Post<Person>("/person");

// POST requests
Person person = new Person()
{
    Id = 1
};
IRestResponse<string> result = client.Delete("/person", person);
IRestResponse<Person> person = client.Delete<Person>("/person");

More docs coming soon....

About

A simple to use REST client for .NET Core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages