...
To create a client use $Rest.Create method by providing the rest RestRequest.Url | service base url.
Example
Code Block | ||
---|---|---|
| ||
var client = $Rest.Create('http://api.geonames.org/'); |
Authenticating Rest Client
Some of rest services may require the authentication. Emakin supports the OpenAuth2 based authentication services and to create a authenticated client please specify the service and identity as below;
This method acquires a authentication token from service and ensures client is authenticated. If token cannot be acquired from service RestClient.EnsureAuthenticated method throws a javascript exception. You can also use RestClient.IsAuthenticated property and RestClient.Authenticate method to perform same operation without error handling.
Example
Code Block | ||
---|---|---|
| ||
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
Code Block | ||
---|---|---|
| ||
var request = client.Request('childrenJSON')
.AddQueryParameter('username', 'demo')
.AddQueryParameter('geonameId', id); |
Example
Every request created with resource url address to added to client base url. Request url may contain parameters to build a dynamic url address like 'sitePath' parameter below;
...
Code Block | ||
---|---|---|
| ||
var request = client.Request("sites/{sitePath}/drives") .AddUrlParameter("sitePath", sitePath) .AddQueryParameter("$select", "id,name"); |
...