kaldesai commented on code in PR #541:
URL:
https://github.com/apache/incubator-kie-kogito-docs/pull/541#discussion_r1496889663
##########
serverlessworkflow/modules/ROOT/pages/core/custom-functions-support.adoc:
##########
@@ -531,7 +531,91 @@ kogito.sw.functions.greet.timeout=5000 <1>
----
<1> Time in milliseconds
-== Custom function types
+== Rest Custom Function
+
+Serverless Workflow Specification defines the
xref:service-orchestration/orchestration-of-openapi-based-services.adoc[OpenAPI
function type], which is the preferred way to interact with existing REST
servers.
+However, sometimes a workflow shoud interact with several REST APIs which are
not described using an OpenAPI specification file. Since generating such file
for these services might be a tedious exercise, {product_name} offers REST
custom type as a shorcut.
+
+When using custom rest, in the function definition you specify the HTTP URI to
be invoked and the HTTP method (get, post, patch or put) to be used, using
`operation` string. When the function is actually invoked you pass the request
arguments as you do when using an OpenAPI function.
+
+The following example shows the declaration of a `rest` function:
+
+.Example of a `rest` function declaration
+[source,json]
+----
+{
+ "functions": [
+ {
+ "name": "multiplyAllByAndSum", <1>
+ "type": "custom", <2>
+ "operation": "rest:post:/numbers/{multiplier}/multiplyByAndSum" <3>
+ }
+ ]
+}
+----
+
+<1> `multiplyAllAndSum` is the function name
+<2> `custom` is the function type
+<3> `rest:post:/numbers/{multiplier}/multiplyByAndSum` is the custom operation
definition. In the custom operation definition:
+* `rest` is the reserved operation keyword that indicates this is a REST call.
+* `post` is the HTTP method.
+* `/numbers/{multiplier}/multiplyByAndSum` is the relative endpoint.
+
+When using relative endpoints you must specify the host as a property. The
format of the host property is `kogito.sw.functions.<function_name>.host`.
Therefore, in this example, the host property key is
`kogito.sw.functions.multiplyAllByAndSum.host`. You might override the default
port (80) if needed by specifying `kogito.sw.functions.multiplyAllAndSum.port`
property.
+
+This particular endpoint expects as body a json object which field `numbers`
is an array of integers, multiplies each item in the array by `multiplier` and
returns the sum of all the multiplied items. Therefore, to invoke it, assuming
the input array is stored in the workflow model as property `inputNumbers`, you
shoud write:
+
+.Example of a `rest` function call
+[source,json]
+----
+{
+ "functionRef": {
+ "refName": "multiplyAllByAndSum",
+ "arguments": {
+ "numbers": "$.inputNumbers"
+ "multiplier": 3 <1>
+ }
+ }
+}
+----
+<4> you replace path and query parameters by specifying an argument which name
is equal to the path or query parameter. The query or path parameter to be
replaced should be enclosed within {} in the endpoint string.
+
+If `inputNumbers` contains `1`, `2` and `3`, the output of the call will be
`1*3+2*3+3*3=18.
Review Comment:
```suggestion
If `inputNumbers` contains `1`, `2`, and `3`, the output of the call will be
`1*3+2*3+3*3=18.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]