dotnet add package RestWrapper --version 3.0.8
NuGet\Install-Package RestWrapper -Version 3.0.8
<PackageReference Include="RestWrapper" Version="3.0.8" />
paket add RestWrapper --version 3.0.8
#r "nuget: RestWrapper, 3.0.8"
// Install RestWrapper as a Cake Addin #addin nuget:?package=RestWrapper&version=3.0.8 // Install RestWrapper as a Cake Tool #tool nuget:?package=RestWrapper&version=3.0.8
A simple C# class library to help simplify sending REST API requests and retrieving responses (RESTful HTTP and HTTPS)
New in v3.0.x
- Minor breaking changes
- Migration from
- Strong naming
- Retrieve query elements from
Test projects are included which will help you exercise the class library.
// simple GET example using RestWrapper; using System.IO; RestRequest req = new RestRequest("http://www.google.com/"); RestResponse resp = req.Send(); Console.WriteLine("Status: " + resp.StatusCode); // response data is in resp.Data
// simple POST example using RestWrapper; using System.IO; RestRequest req = new RestRequest("http://127.0.0.1:8000/api", HttpMethod.POST); RestResponse resp = req.Send("Hello, world!"); Console.WriteLine("Status : " + resp.StatusCode); // response data is in resp.Data
// async methods using RestWrapper; using System.IO; using System.Threading.Tasks; RestRequest req = new RestRequest( "http://127.0.0.1:8000/api", HttpMethod.POST, "text/plain"); // Content type RestResponse resp = await req.SendAsync("Hello, world!"); Console.WriteLine("Status : " + resp.StatusCode); // response data is in resp.Data
// sending form data using RestWrapper; 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"); RestResponse resp = req.Send(form); Console.WriteLine("Status : " + resp.StatusCode);
// deserializing JSON using RestWrapper; RestRequest req = new RestRequest("http://127.0.0.1:8000/api"); RestResponse resp = req.Send(); MyObject obj = resp.DataFromJson<MyObject>();
A Note on Performance and 'localhost'
RestWrapper uses the underlying
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.
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
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.
Thanks go out to the community for their help in making this library great!
Please refer to CHANGELOG.md for version history.
|Product||Versions 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 is compatible. 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.|
|.NET Core||netcoreapp3.0 was computed. netcoreapp3.1 was computed.|
|.NET Standard||netstandard2.1 is compatible.|
|.NET Framework||net461 is compatible. net462 was computed. 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||tizen60 was computed.|
|Xamarin.iOS||xamarinios was computed.|
|Xamarin.Mac||xamarinmac was computed.|
|Xamarin.TVOS||xamarintvos was computed.|
|Xamarin.WatchOS||xamarinwatchos was computed.|
NuGet packages (9)
Showing the top 5 NuGet packages that depend on RestWrapper:
C# SDK for Kvpbase object storage platform
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.
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 is a lightweight SDK for the RESTful API provided by the ArangoDB graph database platform.
Simple class library to send email using Mailgun.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on RestWrapper:
Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
Retrieve query elements from URL using Query property.