Business Console 10.7 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Programming Gadgets | Invoking RESTful Services | Builder Style Pattern for Invoking RESTful Services
 
Builder Style Pattern for Invoking RESTful Services
In this method, you can provide various parameters to the restClient object, and use the invoke method.
Following are the parameters for Builder Style pattern:
Parameter
Description
url
(REQUIRED) This is the relative URL for RESTful service invocation. The serverAlias parameter picks the server to be connected. In the gadget definition, you must define a list of servers (alias) that this gadget must invoke.
method
(OPTIONAL) This can be GET, POST, PUT, DELETE, or any other HTTP Request Method. Default method is GET.
requestData
(OPTIONAL) This can be GET, POST, PUT, DELETE, or any other HTTP Request Method. Default method is GET.
serverAlias
(REQUIRED) This is the alias of the server the gadget must connect to. The list of servers and their alias must be defined in the gadget creation phase or by editing the gadget definition xml file.
remote
(REQUIRED) If this parameter is set to false, then the invocation will always go to the local MWS server. If it is set to true, then the remote server will be evaluated based on the serverAlias provided.
cors
(OPTIONAL) If this parameter is set to true, then a Cross Origin Request will be send to the remote server considering that the CORS headers are already set to allow the request to execute successfully. If it is set to false, then the request will be routed through a Business Console proxy URL to avoid Cross Origin Requests. The default value is true.
scope
(REQUIRED) This is the scope of a gadget under AngularJS context. This will be passed back as part of the success callback function so that further actions can be taken.
gadgetConfig
(REQUIRED) The configuration of the gadget that is passed to the controller is set here.
success
(REQUIRED) The response for the successful invocations will be send to the success callback function. The arguments passed are:
*response: The response object (JSON)
*$scope: The $scope object associated with the gadget controller
failure
(REQUIRED) The response for the failed invocations will be send to error callback function. The arguments passed are:
*response: The response object from the invocation
*$scope: The $scope object associated with the gadget controller
*status: HTTP status code of the response
*headers: {function([headerName])} function retrieves the header object
*config: The configuration object used to generate the request
invoke
This function must be invoked at the end after passing all required parameters.
$scope.restClient.url($scope.URLS.MY_REST_
SERVICE1)
//POINT TO THE RESTful SERVICE TO INVOKE
.serverAlias("IS1")
// POINT TO THE SERVER ALIAS FROM THE GADGET
CONFIGURATION
.remote(true)
// IF LOCAL OR REMOTE CALL
.cors(true)
// IF CORS SUPPORTED FOR REMOTE CALLS ONLY
.scope($scope)
.gadgetConfig(gadgetConfig)
.success(function(response,
$scope){
$scope.responseData =
response;
// HANDLE THE RESPONSE IN A SCOPE OBJECT
}).error(function(response,
$scope,status, headers, config)
{
$scope.eventBus.fireEvent(NotificationConstants.
ERROR,
"Unable to invoke REST ");
// HANDLE ANY ERROR IN INVOCATION
}).invoke();