RestWrapper 3.0.22
dotnet add package RestWrapper --version 3.0.22
NuGet\Install-Package RestWrapper -Version 3.0.22
<PackageReference Include="RestWrapper" Version="3.0.22" />
paket add RestWrapper --version 3.0.22
#r "nuget: RestWrapper, 3.0.22"
// Install RestWrapper as a Cake Addin #addin nuget:?package=RestWrapper&version=3.0.22 // Install RestWrapper as a Cake Tool #tool nuget:?package=RestWrapper&version=3.0.22
RestWrapper
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.0.x
- Minor breaking changes
- Migration from
HttpWebRequest
toHttpClient
- Strong naming
- Retrieve query elements from
RestRequest.Query
property
Test Apps
Test projects are included which will help you exercise the class library.
Examples
// 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 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 | 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. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | 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 | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
-
.NETFramework 4.8
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
-
.NETStandard 2.1
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
-
net6.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
-
net7.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
-
net8.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.9)
NuGet packages (15)
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. |
|
SendWithMailgun
Simple class library to send email and validate email addresses using Mailgun. |
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.0.22 | 220 | 10/29/2024 |
3.0.21 | 418 | 8/27/2024 |
3.0.20 | 2,269 | 5/21/2024 |
3.0.19 | 3,028 | 3/27/2024 |
3.0.18 | 1,020 | 1/16/2024 |
3.0.17 | 1,890 | 11/25/2023 |
3.0.16 | 460 | 11/10/2023 |
3.0.15 | 430 | 11/10/2023 |
3.0.14 | 1,020 | 10/21/2023 |
3.0.12 | 497 | 10/20/2023 |
3.0.11 | 479 | 10/20/2023 |
3.0.10 | 824 | 10/6/2023 |
3.0.9 | 427 | 10/6/2023 |
3.0.8 | 1,417 | 9/4/2023 |
3.0.7 | 517 | 9/4/2023 |
3.0.6 | 581 | 9/1/2023 |
3.0.5 | 570 | 8/31/2023 |
3.0.4 | 539 | 8/31/2023 |
3.0.3 | 1,299 | 8/24/2023 |
3.0.2 | 12,043 | 7/23/2023 |
3.0.1 | 1,280 | 7/12/2023 |
3.0.0 | 696 | 7/12/2023 |
2.3.2 | 3,496 | 3/27/2023 |
2.3.1.1 | 25,284 | 9/4/2022 |
2.3.1 | 2,636 | 8/15/2022 |
2.3.0 | 927 | 8/15/2022 |
2.2.1.15 | 1,672 | 8/11/2022 |
2.2.1.14 | 12,756 | 11/19/2021 |
2.2.1.13 | 27,571 | 11/12/2021 |
2.2.1.12 | 5,156 | 8/14/2021 |
2.2.1.11 | 6,303 | 5/10/2021 |
2.2.1.10 | 4,416 | 2/15/2021 |
2.2.1.9 | 900 | 2/15/2021 |
2.2.1.8 | 1,267 | 2/11/2021 |
2.2.1.7 | 974 | 2/11/2021 |
2.2.1.6 | 2,206 | 1/21/2021 |
2.2.1.5 | 2,589 | 12/28/2020 |
2.2.1.4 | 10,931 | 11/16/2020 |
2.2.1.3 | 4,201 | 11/15/2020 |
2.2.1.2 | 1,345 | 10/24/2020 |
2.2.1.1 | 1,024 | 10/24/2020 |
2.2.1 | 1,135 | 10/23/2020 |
2.2.0 | 1,110 | 10/23/2020 |
2.1.5 | 1,354 | 10/15/2020 |
2.1.4.2 | 13,735 | 9/10/2020 |
2.1.4.1 | 122,872 | 1/17/2020 |
2.1.4 | 14,003 | 12/5/2019 |
2.1.3 | 11,766 | 10/28/2019 |
2.1.2 | 4,096 | 9/22/2019 |
2.0.4 | 4,735 | 6/13/2019 |
2.0.3 | 1,804 | 6/5/2019 |
2.0.2 | 1,333 | 4/30/2019 |
1.0.9 | 6,948 | 3/10/2019 |
1.0.8 | 4,345 | 8/11/2017 |
1.0.7 | 1,603 | 6/23/2017 |
1.0.6 | 1,656 | 5/14/2017 |
1.0.5 | 1,677 | 10/11/2016 |
1.0.4 | 1,586 | 10/7/2016 |
Better support for chunked transfer-encoding and server-sent events.