$Rest¶
Allows interaction with REST services using JSON or XML content types.
REST service operations involve the following objects: RestClient, RestRequest, and RestResponse.
1 |
|
Remarks¶
Creating a REST Client
To create a client, use the $Rest.Create
method, providing the REST service's base URL via the RestRequest.Url property.
Example¶
1 |
|
Authenticating a REST Client Some REST services require authentication. eMakina supports OpenAuth2-based authentication. To create an authenticated client, specify the service and identity as shown below. This method acquires an authentication token from the service and ensures the client is authenticated. If the token cannot be acquired from the service, the
RestClient.EnsureAuthenticated
method throws a JavaScript exception. You can also use the
property and the
method to perform the same operation without error handling.
Example¶
1 |
|
Creating a REST Request After creating the client connection, you can create a REST request and populate parameters as shown below.
Example¶
1 2 3 |
|
Every request created with a resource URL address is appended to the client's base URL. The request URL may contain parameters to build a dynamic URL address, as shown with the
sitePath
parameter below.
Example¶
1 2 3 |
|
Populating a REST Request You can also set HTTP headers using the
method. Some REST methods require a JSON or XML-based body. You can specify the content of the request using the
or
methods.
Fetching a REST Response After populating the request, you can call the
method to execute it and fetch the
object. The
Execute
method does not perform any error checking by default. To ensure the request was executed successfully, use the
method to specify the expected status code.
Example¶
1 2 3 4 5 6 |
|
REST Request Methods You can also use the
,
,
,
, and
methods to call the service with the corresponding HTTP method. Alternatively, you can manually set the
before executing the request.
If the service always returns JSON or XML, you can use the
or
methods to fetch the response as a JSON object or an XML node, respectively.
Example¶
1 2 3 |
|