Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
var request = client.Request('childrenJSON')
                .AddQueryParameter('username', 'demo')
                .AddQueryParameter('geonameId', id);

Example

Code Block
languagejs
var request = client.Request("sites/{sitePath}/drives")
                .AddUrlParameter("sitePath", sitePath)
                .AddQueryParameter("$select", "id,name");

Populating Rest Request

You may also set http headers with

...

RestRequest.AddHeader

...

method.

Some rest methods requires JSON or XML based body and you can specify the content of request with

...

RestRequest.AddObject

...

or

...

RestRequest.AddXml

...

methods.

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

Code Block
languagejs
var response = request.Execute();

if (response.StatusCode == "OK") {
    var val = response.GetHeader('X-Header');
    var obj = response.ToJson();
}

Rest Request Methods

You can also use

...

RestRequest.Get

...

, RestRequest.Delete

...

,

...

RestRequest.Put,

...

RestRequest.Post,

...

RestRequest.Patch

...

methods to call service with corresponding method or you can manually set the

...

RestRequest.Method

...

before executing.

If service always returns JSON or XML you can use

...

RestRequest.ExecuteJson

...

or

...

RestRequest.ExecuteXml

...

method to fetch response as JSON object or XML navigator.

Example

Code Block
languagejs
var object = request.ExecuteJson();

// object.person.name;

...