Skip to content

Creating Web Service Components

  1. Use the Web Service Component Editor to create a new Web Service Component.

  2. Choose a unique Component Name for the component you wish to create.

  3. Populate the Restful Web Service Function field with the javascript code that implements the function(s).

  4. Save the component

Use the following information to setup a new Web Service Component:

Component Name: ws-test-service

Restful Web Service Functions:

{
  componentName : "ws-test-service",

  getGreeting : function(args) {
      var deferred = q.defer();

      const componentName = this.componentName;
      const funcName = "getGreeting";
      var ref = "componentFunction: " + componentName + "." + funcName;
      logger.info(ref + ", args: " + JSON.stringify(args));

      var docs = {"greeting": "hello world"};
      logger.info(ref + ", response: " + JSON.stringify(docs));
      deferred.resolve(docs);

     return deferred.promise;
  },

  echoParameters : function(args) {
      var deferred = q.defer();

      const componentName = this.componentName;
      const funcName = "echoParameters";
      var ref = "componentFunction: " + componentName + "." + funcName;
      logger.info(ref + ", args: " + JSON.stringify(args));

      if (!args) {args = []}
      var docs = {"parameters": args};
      logger.info(ref + ", response: " + JSON.stringify(docs));
      deferred.resolve(docs);

     return deferred.promise;
  },

  sortParameters : function(args) {
      var deferred = q.defer();

      const componentName = this.componentName;
      const funcName = "sortParameters";
      var ref = "componentFunction: " + componentName + "." + funcName;
      logger.info(ref + ", args: " + JSON.stringify(args));

      if (args) {
        args.sort();
      } else {
        args = [];
      }
      var docs = {"parameters": args};
      logger.info(ref + ", response: " + JSON.stringify(docs));
      deferred.resolve(docs);

     return deferred.promise;
  }
}

Once created, the functions will be available via a RestFul Web Service Call.

Refer to the execute API documentation for examples on how to call these functions using curl.