Execute REST request building block

Introduction

This action can be utilized as the lowest level action with any form of REST communication, to be called by higher level actions or workflows.  It encapsulate the REST communication with the vRO REST plugin into one spot, checks for errors always, and provides a simplified mechanism of working with REST calls within vRO.  Callers of this REST action get to operate at a higher level of abstraction which greatly improves readability as the caller gets to just list out the REST communication details from an API standpoint, rather than mixing in the mechanism by which it's done at the vRO level (ie: vRO REST plugin).

The action makes the assumption (and sets appropriate headings) that the body will be JSON and that the accepted response is JSON.  Since vRO is developed with JavaScript, the action also makes the assumption that the body is an actual JavaScript object which is serialized to JSON before sending it off, which makes the construction of the body much simpler.

Example Usage

The following is an example of another action which is constructed as a building block itself to encapsulate a specific REST operation with a particular system.  The system is fictitious to illustrate the various elements of the call to the provided executeRestRequest action.  

// VMware vRealize Orchestrator action sample - "createNewNetwork"
//
// networkAddressInput - string - Network address such as 192.168.1.0
// subnetMaskInput - string - Subnet mask such as 255.255.255.0
//
// Return type: Any (JavaScript object depicting newly created network and details)
//

var endpointName = "IPAM-SYSTEM";
var operation = "/networks/" + networkAddressInput;
var method = "PUT";
var body = {
    subnetMask: subnetMaskInput 
};

var additionalHeaders = new Properties({
    "networkView":  "default"
});


var networkDetails = System.getModule("com.companyName.rest.common").executeRestRequest(endpointName, method, operation, body, additionalHeaders);
System.debug("Default gateway for new network = " + networkDetails.gateway);

return networkDetails;

The example provided could be further optimized if multiple operations are performed to the same REST system.  Rather than calling executeRestRequest directly, this createNewNetwork example action could call a new executeRestRequestForIPAMsystem which in turn would call the executeRestRequest, yet executeRestRequestForIPAMsystem would be responsible for defining the "endpointName" in one spot ("IPAM-SYSTEM") as well as always adding the same additional header of networkView.


Sign in to be able to add comments.

Comments 0