RestWrapper 3.1.5

dotnet add package RestWrapper --version 3.1.5
                    
NuGet\Install-Package RestWrapper -Version 3.1.5
                    
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="RestWrapper" Version="3.1.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RestWrapper" Version="3.1.5" />
                    
Directory.Packages.props
<PackageReference Include="RestWrapper" />
                    
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 RestWrapper --version 3.1.5
                    
#r "nuget: RestWrapper, 3.1.5"
                    
#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.
#addin nuget:?package=RestWrapper&version=3.1.5
                    
Install RestWrapper as a Cake Addin
#tool nuget:?package=RestWrapper&version=3.1.5
                    
Install RestWrapper as a Cake Tool

alt tag

RestWrapper

NuGet Version NuGet

A simple C# class library to help simplify sending REST API requests and retrieving responses (RESTful HTTP and HTTPS)

Special Thanks

Thanks go out to the community for their help in making this library great!

@nhaberl @jmkinzer @msasanmh @lanwah @nhaberl

New in v3.1.x

  • Minor breaking changes
  • Better internal support for chunked-transfer encoding
  • Remove non-async methods

Test Apps

Test projects are included which will help you exercise the class library.

Examples

// simple GET example
using RestWrapper;
using System.IO;

using (RestRequest req = new RestRequest("http://www.google.com/"))
{
	using (RestResponse resp = await req.SendAsync())
	{
		Console.WriteLine("Status: " + resp.StatusCode);
		// response data is in resp.Data
	}
}
// simple POST example
using RestWrapper;
using System.IO;

using (RestRequest req = new RestRequest("http://127.0.0.1:8000/api", HttpMethod.POST))
{
	using (RestResponse resp = await req.SendAsync("Hello, world!"))
	{
		Console.WriteLine("Status : " + resp.StatusCode);
		// response data is in resp.Data
	}
}
// sending form data
using RestWrapper;

using (RestRequest req = new RestRequest("http://127.0.0.1:8000/api", HttpMethod.POST))
{
	Dictionary<string, string> form = new Dictionary<string, string>();
	form.Add("foo", "bar");
	form.Add("hello", "world how are you");

	using (RestResponse resp = await req.SendAsync(form))
	{
		Console.WriteLine("Status : " + resp.StatusCode);
	}
}
// deserializing JSON
using RestWrapper;

using (RestRequest req = new RestRequest("http://127.0.0.1:8000/api"))
{
	using (RestResponse resp = await req.SendAsync())
	{
		MyObject obj = resp.DataFromJson<MyObject>();
	}
}

A Note on Performance and 'localhost'

RestWrapper uses the underlying HttpWebRequest and HttpWebResponse classes from System.Net. When using localhost as the target URL, you may notice in Wireshark that HttpWebRequest will first attempt to connect to the IPv6 loopback address, and not all services listen on IPv6. This can create a material delay of more than 1 second. In these cases, it is recommended that you use 127.0.0.1 instead of localhost for these cases.

Basic Telemetry

The RestResponse object contains a property called Time that can be useful for understanding how long a request took to complete.

RestRequest req = new RestRequest("https://www.cnn.com");
RestResponse resp = req.Send();
Console.WriteLine("Start    : " + resp.Time.Start);
Console.WriteLine("End      : " + resp.Time.End);
Console.WriteLine("Total ms : " + resp.Time.TotalMs + "ms");

Deserializing Response Data

The method RestResponse.DataFromJson<T>() will deserialize using System.Text.Json. You can override the RestResponse.SerializationHelper property with your own implementation of ISerializationHelper if you wish to use your own deserializer. Thank you @nhaberl for the suggestion.

Version History

Please refer to CHANGELOG.md for version history.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
.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 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  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 (17)

Showing the top 5 NuGet packages that depend on RestWrapper:

Package Downloads
KvpbaseSDK

C# SDK for Kvpbase object storage platform

Komodo.Sdk

Client SDK in C# for Komodo. Please either install Komodo.Daemon to integrate search within your application, or Komodo.Server to run a standalone server if you wish to use this client SDK. Komodo is an information search, metadata, storage, and retrieval platform.

GoogleMapsClient

I needed a simple way to parse addresses and resolve coordinates to an address. Plug in a Google Maps API key and you're all set.

ArangoDBLite

ArangoDBLite is a lightweight SDK for the RESTful API provided by the ArangoDB graph database platform.

SendWithBrevo

A simple C# class library to help simplify sending emails using Brevo.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RestWrapper:

Repository Stars
dotnet/WatsonWebserver
Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
Version Downloads Last updated
3.1.5 197 3/10/2025
3.1.4 302 1/22/2025
3.1.3 308 12/13/2024
3.1.2 279 12/10/2024
3.1.1 110 12/10/2024
3.1.0 394 12/2/2024
3.0.22 542 10/29/2024
3.0.21 2,218 8/27/2024
3.0.20 2,433 5/21/2024
3.0.19 3,827 3/27/2024
3.0.18 1,144 1/16/2024
3.0.17 2,707 11/25/2023
3.0.16 470 11/10/2023
3.0.15 440 11/10/2023
3.0.14 1,133 10/21/2023
3.0.12 505 10/20/2023
3.0.11 489 10/20/2023
3.0.10 837 10/6/2023
3.0.9 435 10/6/2023
3.0.8 1,498 9/4/2023
3.0.7 526 9/4/2023
3.0.6 588 9/1/2023
3.0.5 579 8/31/2023
3.0.4 550 8/31/2023
3.0.3 1,341 8/24/2023
3.0.2 16,273 7/23/2023
3.0.1 1,289 7/12/2023
3.0.0 710 7/12/2023
2.3.2 3,608 3/27/2023
2.3.1.1 28,414 9/4/2022
2.3.1 2,660 8/15/2022
2.3.0 950 8/15/2022
2.2.1.15 1,697 8/11/2022
2.2.1.14 12,790 11/19/2021
2.2.1.13 29,854 11/12/2021
2.2.1.12 5,183 8/14/2021
2.2.1.11 6,452 5/10/2021
2.2.1.10 4,442 2/15/2021
2.2.1.9 925 2/15/2021
2.2.1.8 1,293 2/11/2021
2.2.1.7 1,001 2/11/2021
2.2.1.6 2,231 1/21/2021
2.2.1.5 2,614 12/28/2020
2.2.1.4 10,961 11/16/2020
2.2.1.3 4,237 11/15/2020
2.2.1.2 1,370 10/24/2020
2.2.1.1 1,048 10/24/2020
2.2.1 1,159 10/23/2020
2.2.0 1,139 10/23/2020
2.1.5 1,381 10/15/2020
2.1.4.2 13,773 9/10/2020
2.1.4.1 124,907 1/17/2020
2.1.4 14,033 12/5/2019
2.1.3 11,799 10/28/2019
2.1.2 4,442 9/22/2019
2.0.4 4,765 6/13/2019
2.0.3 1,834 6/5/2019
2.0.2 1,365 4/30/2019
1.0.9 6,990 3/10/2019
1.0.8 4,468 8/11/2017
1.0.7 1,681 6/23/2017
1.0.6 1,736 5/14/2017
1.0.5 1,754 10/11/2016
1.0.4 1,665 10/7/2016

Better support for chunked transfer-encoding.