Business Console 10.7 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Programming Gadgets | Invoking RESTful Services | Steps to Invoke RESTful Services
 
Steps to Invoke RESTful Services
1. In the URLS object, define the URL required for invoking the RESTful service.
URLS:{
MY_REST_SERVICE1:{url: '/rest/rs/myRest1',method:'GET',
isArray:true},
MY_REST_SERVICE2:{url: '/rest/rs/myRest2',method:'GET',
isArray:true}
},
2. Define a function (for example, invokeMyRestFunction) inside the defineScope block that makes the actual invocation.
this.$scope.invokeMyRestFunction= function(gadgetConfig) {
var $scope = this;

$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();
}
There are two methods to invoke a RESTful service using URLs:
Method
Description
CORS support for RESTful services
This method invokes the RESTful services using direct URL. For more information about Cross Origin Resource Sharing (CORS), see Using CORS Support for Invoking RESTful Services
Business Console proxy for RESTful services
This method invokes the RESTful services using Business Console proxy, in case the remote server cannot be configured to support the CORS headers. For more information about Business Console proxy, see Using Business Console Proxy for Invoking RESTful Services
3. Call the invokeMyRestFunction function from init (if the RESTful service needs to be called on Gadget load) or from any other place depending on the business logic.
init : function($scope, restClient,eventBus,log,config) {
...
this.$scope.invokeMyRestFunction(config);
...
},
As a part of the gadget frame work, there are two methods to invoke a RESTful service:
Method
Description
Builder Style pattern RESTful service invocation
This method provides various parameters to the restClient object to invoke RESTful services. For more information about the parameters for Builder Style pattern, see Builder Style Pattern for Invoking RESTful Services
Traditional RESTful service invocation
This method uses the invokeREST function to invoke RESTful services. For more information about the invokeREST function, see Traditional Service for Invoking RESTful Services