Code Monkey home page Code Monkey logo

rest.net's Introduction

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

rest.net's People

Contributors

developer82 avatar

Watchers

James Cloos avatar

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.