Rest

Send a Rest call and return results in JSON.

Constructors

public class RestClient

Properties

public Dictionary<string, string> Headers

Dictionary of header keys and values to pass with the Rest call.

public Dictionary<string, string> QueryString

Dictionary of query string key and values to pass with the Rest call

Methods

public Response Get<Response>(string url, string endPoint)

Makes a GET request to a Rest endpoint.

Response

The object type to deserialise the JSON into for returning.

string url

Remote URL to call without the endpoint api name.

string endPoint

The API endpoint to call.

public Response Post<Send, Response>(string url, string endPoint, Send data)

Makes a POST request to a Rest endpoint.

Send

The object type containing data to serialise into JSON to send to the remote endpoint.

Response

The object type to deserialise the JSON into for returning.

string url

Remote URL to call without the endpoint api name.

string endPoint

The API endpoint to call.

Send data

The object containing data to serialise into JSON to send to the remote endpoint.

Example GET

C#
var rc = new RestClient();

rc.Headers.Add("header1", "MyHeaderValue1");
rc.Headers.Add("header2", "MyHeaderValue2");

var x = rc.Get(AppValue.ApiServer, "MyApi");

Example POST

C#
public class MyData
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}


MyData data = new MyData() {
Prop1 = "MyValue1",
Prop1 = "MyValue2"
};

var rc = new RestClient();

rc.Headers.Add("header1", "MyHeaderValue1");
rc.Headers.Add("header2", "MyHeaderValue2");

var x = rc.Post(AppValue.ApiServer, "MyApi", data);