- Easliy Create Fluent SDK's
- Unit Testing
- Post Json
- Post Forms
- Post Files
- Retry Requests
- Twitter SDK
- Raw HTTP
- Passthrough HttpClient
RestClient targets .NET Standard 2.0 therefore supports Windows, Linux, Mac and Xamarin (iOS, Android and UWP).
.NET 5.0 and .NET 6.0 supported All versions of .NET Core supported All versions of legacy .NET Framework > 4.6.1 supported
> dotnet add package DalSoft.RestClient
PM> Install-Package DalSoft.RestClient
You start by new'ing up the RestClient and passing in the base uri for your RESTful API.
For example if your wanted to perform a GET on https://jsonplaceholder.typicode.com/users/1 you would do the following:
Static Typed Rest Client
For the Static typed Rest Client just pass a string representing the resource you want access to the Resource method, and then call the HTTP method you want to use.
var client = new RestClient("https://jsonplaceholder.typicode.com"); User user = await client.Resource("users/1").Get(); Console.WriteLine(user.Name);
Dynamicaly Typed Rest Client
For the Dynamicaly typed Rest Client chain members that would make up the resource you want to access - ending with the HTTP method you want to use.
dynamic client = new RestClient("https://jsonplaceholder.typicode.com"); var user = await client.Users(1).Get(); Console.WriteLine(user.name);
Note all HTTP methods are async
- Version 4.0 Static Typing and Resource Expressions
- Version 3.3.0 IHttpClientFactory Goodness
- Version 3.0 Pipeline Awesomeness
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, making it trivial to create REST requests using a lot less code.
Originally created to remove the boilerplate code involved in making REST requests using code that is testable. I know there are a couple of REST clients out there but I wanted the syntax to look a particular way with minimal fuss.
RestClient is biased towards posting and returning JSON - if you don't provide Accept and Content-Type headers then they are set to application/json by default See Working with non JSON content.
DalSoft.RestClient is built using the following great open source projects:
DalSoft.RestClient is inspired by and gives credit to: