DalSoft.RestClient 3.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DalSoft.RestClient --version 3.3.0
                    
NuGet\Install-Package DalSoft.RestClient -Version 3.3.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="DalSoft.RestClient" Version="3.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DalSoft.RestClient" Version="3.3.0" />
                    
Directory.Packages.props
<PackageReference Include="DalSoft.RestClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DalSoft.RestClient --version 3.3.0
                    
#r "nuget: DalSoft.RestClient, 3.3.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.
#:package DalSoft.RestClient@3.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DalSoft.RestClient&version=3.3.0
                    
Install as a Cake Addin
#tool nuget:?package=DalSoft.RestClient&version=3.3.0
                    
Install as a Cake Tool

Getting Started

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 https://api.github.com/users/dalsoft/repos getting a list of my repositories:

dynamic client = new RestClient("https://api.github.com");

var repositories = await client
   .Headers(new { UserAgent = "MyClient" }) //GitHub requires a User-Agent to be set
   .users.dalsoft.repos.Get();
   
foreach (var repo in repositories)
   Console.WriteLine(repo.name);

Note all HTTP methods are async

New in Version 3.3.0 IHttpClientFactory Goodness!

In version 3.3.0 we added support for .NET Core's 2.1 IHttpClientFactory.

First register your RestClient as a service in Startup.cs.

public class Startup
{
   public void ConfigureServices(IServiceCollection services)
   {
      services.AddRestClient("https://api.github.com", new Headers(new { UserAgent = "MyClient" }));
   }
}

Then inject IRestClientFactory into your controller, which is how we support IHttpClientFactory.

public class GitHubController : Controller
{
   private readonly IRestClientFactory _restClientFactory;
        
   public GitHubController(IRestClientFactory restClientFactory)
   {
      _restClientFactory = restClientFactory;
   }

   [Route("github/users/dalsoft"), HttpGet]
   public async Task<List<Repository>> CreateClient()
   {
      dynamic restClient = _restClientFactory.CreateClient();
            
      var repositories = await restClient.users.dalsoft.repos.Get();
            
      return repositories;
   }        
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on DalSoft.RestClient:

Package Downloads
RoomerSDK

SDK for Roomer API

DalSoft.RestClient.Testing

Use DalSoft.RestClient with ASP.NET Core In-Memory Test Server for integration tests.

RamApidotnet

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on DalSoft.RestClient:

Repository Stars
MelbourneDeveloper/RestClient.Net
The safest way to make REST calls in C# with an MCP Generator
kitamstudios/rust-analyzer.vs
Rust language support for Visual Studio 2022
Version Downloads Last Updated
4.4.2 30,559 9/2/2024
4.4.1 67,216 12/2/2021
4.4.0 28,565 12/18/2020
4.3.0 2,575 11/25/2020
4.2.1 7,827 9/24/2020
4.2.0 24,519 10/26/2019
4.1.0 13,914 8/24/2019
4.0.0 2,861 8/4/2019
3.3.2 20,187 12/3/2018
3.3.1 3,145 10/29/2018
3.3.0 5,174 7/11/2018
3.2.3 2,651 4/25/2018
3.2.2 49,524 5/4/2017
3.1.1 2,364 4/23/2017
3.1.0 2,325 4/20/2017
3.0.3 3,148 2/27/2017
3.0.2 2,447 2/23/2017
2.0.4 5,481 12/2/2016
2.0.2 3,156 11/2/2016
2.0.1 2,350 10/28/2016
2.0.0 3,166 10/27/2016
1.0.10 4,855 6/14/2016
1.0.9 6,161 8/28/2015
1.0.8 2,124 8/28/2015
1.0.7.27011 2,516 8/3/2015
1.0.7.15372 2,146 8/28/2015
1.0.6 2,341 5/11/2015
1.0.5.2623 2,309 4/25/2015
1.0.4.41175 2,233 2/1/2015
1.0.4.41083 2,334 4/24/2015
1.0.3.29240 2,157 1/21/2015
1.0.2.31019 2,171 1/20/2015
1.0.1 2,185 1/15/2015
1.0.0 2,244 1/14/2015

* Added DI support for .NET Core 2.1 IHttpClientFactory
     * Made Header type for RestClient ctor and .Headers() for even cleaner code going forward!
     * Fix for #2 'content.ReadAsStringAsync().Result should be awaitable'