Skip to content

Create

Creates a new RestClient instance.

1
$Rest.Create(url: string, service?: string, scope?: string, identity?: ( string | Identity )):RestClient

Parameters

string url
    The base URL of the REST service.

string service optional
    The name of the service to authenticate with. Optional.

string scope optional
    The scope of the REST operation. Optional.

( string | Identity ) identity optional
    The identity to impersonate, as an Identity object or its ID. Optional.

Returns

A new RestClient instance.

Remarks

The service, scope, and identity parameters are optional. If service is not specified, the client is not authenticated.

Examples

Read JSON from a service

1
2
3
4
5
var client = $Rest.Create('https://api.example.com/');

var customer = client.Request('customers/{id}')
    .AddUrlParameter('id', $Xml.Evaluate('Customer/Id'))
    .ExecuteJson();

Create an authenticated client

1
2
// 'Office365' is a service configured in the domain settings
var client = $Rest.Create('https://graph.microsoft.com/v1.0/', 'Office365', '', $Initiator);

See Also