Overview
Allows to call rest services with JSON or XML content types. Rest service operations consist of objects RestClient and RestRequestRestResponse.const $Rest;
Creating Rest Client
To create a client use $Rest.Create method by providing the rest RestRequest.Url | service base url.
Example
var client = $Rest.Create('http://api.geonames.org/');
Example
var client = $Rest.Create('https://graph.microsoft.com/v1.0/', 'Office365', '', $WorkItem.CompletedBy).EnsureAuthenticated();
Creating Rest Request
After creating client connection you can create rest request and populate parameters as below;
Example
var request = client.Request('childrenJSON') .AddQueryParameter('username', 'demo') .AddQueryParameter('geonameId', id);
Example
var request = client.Request("sites/{sitePath}/drives") .AddUrlParameter("sitePath", sitePath) .AddQueryParameter("$select", "id,name");
Fetching Rest Response
After Request populated you can call the RestRequest.Execute method to execute and fetch RestResponse object. Execute method by default does not perform any error check. If you want to be sure request has successfully executed please use RestRequest.Expect method to specify expected status code.
Example
var response = request.Execute(); if (response.StatusCode == "OK") { var val = response.GetHeader('X-Header'); var obj = response.ToJson(); }
Example
var object = request.ExecuteJson(); // object.person.name;