RestWrapper 1.0.8

A simple C# wrapper for making REST API requests (RESTful HTTP and HTTPS)

There is a newer version of this package available.
See the version list below for details.
Install-Package RestWrapper -Version 1.0.8
dotnet add package RestWrapper --version 1.0.8
<PackageReference Include="RestWrapper" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RestWrapper --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RestWrapper

A simple C# class library to help simplify RESTful HTTP requests and responses.

Test App

A test project is included which will help you exercise the class library.

Available APIs

Two static methods exist: SendRequest and SendRequestSafe. The differences are as follows:

  • SendRequest will throw any exception encountered to the caller
  • SendRequestSafe will take any WebException and create a RestResponse object from it. Other exceptions are thrown to the caller

Example

using RestWrapper;

//
// Simple GET with No Credentials
//
RestResponse resp = RestRequest.SendRequest(
	"http://www.github.com/",	// URL
	null, 						// content-type
	"GET",						// verb/method
	null, null, false, 			// user, password, encode
	null, 						// headers
	null);						// byte array data

//
// Enumerate response
//
Console.WriteLine(
	"Received " + resp.StatusCode + " (" + resp.ContentLength + " bytes) " +
	"with data: " + Encoding.UTF8.GetString(resp.Data));

//
// POST with Headers and Credentials
//
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("x-custom-header", "my-custom-value");
byte[] data = Encoding.UTF8.GetBytes("some-field=some-value&hello=world");

RestResponse resp = RestRequest.SendRequest(
	"https://my.server.com/form",			// URL
	"application/x-www-form-urlencoded",	// content-type
	"POST",									// verb/method
	"my-username", "my-password", true, 	// user, password, encode
	headers,								// headers
	data);									// byte array data

//
// Enumerate response
//
Console.WriteLine(resp.ToString());		// Easy peasy

RestWrapper

A simple C# class library to help simplify RESTful HTTP requests and responses.

Test App

A test project is included which will help you exercise the class library.

Available APIs

Two static methods exist: SendRequest and SendRequestSafe. The differences are as follows:

  • SendRequest will throw any exception encountered to the caller
  • SendRequestSafe will take any WebException and create a RestResponse object from it. Other exceptions are thrown to the caller

Example

using RestWrapper;

//
// Simple GET with No Credentials
//
RestResponse resp = RestRequest.SendRequest(
	"http://www.github.com/",	// URL
	null, 						// content-type
	"GET",						// verb/method
	null, null, false, 			// user, password, encode
	null, 						// headers
	null);						// byte array data

//
// Enumerate response
//
Console.WriteLine(
	"Received " + resp.StatusCode + " (" + resp.ContentLength + " bytes) " +
	"with data: " + Encoding.UTF8.GetString(resp.Data));

//
// POST with Headers and Credentials
//
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("x-custom-header", "my-custom-value");
byte[] data = Encoding.UTF8.GetBytes("some-field=some-value&hello=world");

RestResponse resp = RestRequest.SendRequest(
	"https://my.server.com/form",			// URL
	"application/x-www-form-urlencoded",	// content-type
	"POST",									// verb/method
	"my-username", "my-password", true, 	// user, password, encode
	headers,								// headers
	data);									// byte array data

//
// Enumerate response
//
Console.WriteLine(resp.ToString());		// Easy peasy

Release Notes

Variable casing, conversion methods, suppor for OPTIONS

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.1.0 16 9/15/2019
2.0.4 111 6/13/2019
2.0.3 122 6/5/2019
2.0.2 135 4/30/2019
1.0.9 254 3/10/2019
1.0.8 513 8/11/2017
1.0.7 333 6/23/2017
1.0.6 317 5/14/2017
1.0.5 378 10/11/2016
1.0.4 310 10/7/2016
Show less