Execute a Web Service Component Function
POST /api/execute
Executes a Web Service Component Function
Permission to execute Component Functions is based on standard Formbird document key principles.
Arguments
-
your apiKey, for example:
bf5b0500-9332-11e6-9c03-853f647fe4a4
-
json document containing execution instructions, for example:
json
{
"componentDocumentName": "ws-test-service",
"functionName": "sortParameters",
"functionParameters": [9,5,7,2,1,8,6,4,3,0]
}
value | required | description |
---|---|---|
componentDocumentName | true | Name of component Document containing the web service |
functionName | true | Name of the function being called in the web service |
functionParameters | false | An array of parameters to pass to the function being called |
The Request examples below refer to an example ws-test-service
component which provides the following functions: getGreeting
, echoParameters
, and sortParameters
. The below snippet of code shows how these functions are implemented in the ws-test-service
component.
Code Snippet taken from a ws-test-service
Component Document
{
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;
}
}
Example Request - calling getGreeting
curl http://localhost:3000/api/execute \
-H "Content-Type: application/json;charset=UTF-8" \
-H "apiKey: bf5b0500-9332-11e6-9c03-853f647fe4a4" \
-d "{\"componentDocumentName\": \"ws-helloworld\", \"functionName\": \"getGreeting\"}"
Example Response
{
"greeting": "hello world"
}
Example Request - calling echoParameters
curl http://localhost:3000/api/execute \
-H "Content-Type: application/json;charset=UTF-8" \
-H "apiKey: bf5b0500-9332-11e6-9c03-853f647fe4a4" \
-d "{\"componentDocumentName\": \"ws-test-service\", \"functionName\": \"echoParameters\", \"functionParameters\": [9,5,7,2,1,8,6,4,3,0]}"
Example Response
{
"parameters": [9,5,7,2,1,8,6,4,3,0]
}
Example Request - calling sortParameters
curl http://localhost:3000/api/execute \
-H "Content-Type: application/json;charset=UTF-8" \
-H "apiKey: bf5b0500-9332-11e6-9c03-853f647fe4a4" \
-d "{\"componentDocumentName\": \"ws-test-service\", \"functionName\": \"sortParameters\", \"functionParameters\": [9,5,7,2,1,8,6,4,3,0]}"
Example Response
{
"parameters": [0,1,2,3,4,5,6,7,8,9]
}