Inspired by Simple.Data and AngularJS's $http service, DalSoft.RestClient is a very lightweight wrapper around System.Net.HttpClient that uses the dynamic features of .NET 4 to provide a fluent way of accessing RESTFul API's.
Originally created to remove the boilerplate code involved in creating integration tests and SDK's for RESTFul API's. I know there are a couple of dynamic rest clients out there but I wanted the syntax to look a particular way, and I wanted it to be particularly useful for testing.
DalSoft.RestClient is biased towards RESTFul API's returning JSON - if you don't provide Accept and Content-Type headers then they are set to
application/json
. See Working with non JSON content
DalSoft.RestClient targets .NET Standard 1.4 therefore supports Windows, Linux, Mac and Xamarin (iOS, Android and UWP).
Install via NuGet
PM> Install-Package DalSoft.RestClient
You start by new'ing up the RestClient and passing in the base uri for your RESTful API. Then simply chain members that would make up the resource you want to access - ending with the HTTP method you want to use. The example below will perform a GET on http://jsonplaceholder.typicode.com/users/:
dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
await client.Users.Get();
Note all HTTP methods are async
See Configuration, Plugins and Pipeline
Since version 3.1 the DefaultRequestHeaders Dictionary is readonly the only way to add DefaultHeaders is passing a Dictionary to the constructor. You can add/override the headers on a per request basis using the Headers method.
client.DefaultRequestHeaders.Add("Accept", "application/json"); //Not supported since version 3.1
Advanced
DalSoft.RestClient is built using the following great open source projects:
DalSoft.RestClient is inspired by and gives credit to: