RestWrapper 3.1.4
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.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.
Showing the top 20 packages that depend on RestWrapper.
| Packages | Downloads |
|---|---|
|
S3Lite
Lightweight Amazon S3 client without all the heft and dependency drag of the official library.
|
8 |
Better support for chunked transfer-encoding.
.NET Framework 4.6.2
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
.NET Framework 4.8
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
.NET 6.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
.NET 8.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
.NET Standard 2.0
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
.NET Standard 2.1
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
- Timestamps (>= 1.0.11)
| Version | Downloads | Last updated |
|---|---|---|
| 3.1.8 | 0 | 10/04/2025 |
| 3.1.7 | 0 | 10/01/2025 |
| 3.1.6 | 0 | 09/19/2025 |
| 3.1.5 | 0 | 03/10/2025 |
| 3.1.4 | 5 | 01/08/2026 |
| 3.1.3 | 0 | 12/13/2024 |
| 3.1.2 | 0 | 12/10/2024 |
| 3.1.1 | 0 | 12/10/2024 |
| 3.1.0 | 0 | 12/02/2024 |
| 3.0.22 | 0 | 10/29/2024 |
| 3.0.21 | 0 | 08/27/2024 |
| 3.0.20 | 0 | 05/21/2024 |
| 3.0.19 | 0 | 03/27/2024 |
| 3.0.18 | 0 | 01/16/2024 |
| 3.0.17 | 0 | 11/25/2023 |
| 3.0.16 | 0 | 11/10/2023 |
| 3.0.15 | 0 | 11/10/2023 |
| 3.0.14 | 0 | 10/21/2023 |
| 3.0.12 | 0 | 10/20/2023 |
| 3.0.11 | 0 | 10/20/2023 |
| 3.0.10 | 0 | 10/06/2023 |
| 3.0.9 | 0 | 10/06/2023 |
| 3.0.8 | 0 | 09/04/2023 |
| 3.0.7 | 0 | 09/04/2023 |
| 3.0.6 | 0 | 09/01/2023 |
| 3.0.5 | 0 | 08/31/2023 |
| 3.0.4 | 0 | 08/31/2023 |
| 3.0.3 | 0 | 08/24/2023 |
| 3.0.2 | 0 | 07/23/2023 |
| 3.0.1 | 0 | 07/12/2023 |
| 3.0.0 | 0 | 07/12/2023 |
| 2.3.2 | 0 | 03/27/2023 |
| 2.3.1.1 | 0 | 09/04/2022 |
| 2.3.1 | 0 | 08/15/2022 |
| 2.3.0 | 0 | 08/15/2022 |
| 2.2.1.15 | 0 | 08/11/2022 |
| 2.2.1.14 | 0 | 11/19/2021 |
| 2.2.1.13 | 0 | 11/12/2021 |
| 2.2.1.12 | 0 | 08/14/2021 |
| 2.2.1.11 | 0 | 05/10/2021 |
| 2.2.1.10 | 0 | 02/15/2021 |
| 2.2.1.9 | 0 | 02/15/2021 |
| 2.2.1.8 | 0 | 02/11/2021 |
| 2.2.1.7 | 0 | 02/11/2021 |
| 2.2.1.6 | 0 | 01/21/2021 |
| 2.2.1.5 | 0 | 12/28/2020 |
| 2.2.1.4 | 0 | 11/16/2020 |
| 2.2.1.3 | 0 | 11/15/2020 |
| 2.2.1.2 | 0 | 10/24/2020 |
| 2.2.1.1 | 0 | 10/24/2020 |
| 2.2.1 | 0 | 10/23/2020 |
| 2.2.0 | 0 | 10/23/2020 |
| 2.1.5 | 0 | 10/15/2020 |
| 2.1.4.2 | 0 | 09/10/2020 |
| 2.1.4.1 | 0 | 01/17/2020 |
| 2.1.4 | 0 | 12/05/2019 |
| 2.1.3 | 0 | 10/28/2019 |
| 2.1.2 | 0 | 09/22/2019 |
| 2.0.4 | 0 | 06/13/2019 |
| 2.0.3 | 0 | 06/05/2019 |
| 2.0.2 | 0 | 04/30/2019 |
| 1.0.9 | 0 | 03/10/2019 |
| 1.0.8 | 0 | 08/11/2017 |
| 1.0.7 | 0 | 06/23/2017 |
| 1.0.6 | 0 | 05/14/2017 |
| 1.0.5 | 0 | 10/11/2016 |
| 1.0.4 | 0 | 10/07/2016 |