Actions

Typed parameters

This example shows the ‘Hello world’ example with typed input and output Parameters.

It shows how to:

  • declare input and output parameters on the action ‘hello_world’ using a simple, single-line format.
  • add two input parameters, ‘name’ and ‘place’, both of type ‘string’ to the ‘hello_world’ action.
  • add an ‘integer’ parameter, ‘age’, to the action.
  • add a ‘float’ parameter, ‘height’, to the action.
  • add two output parameters, ‘greeting’ and ‘details’, both of type ‘string’, to the action.

Manifest File

Example: ‘Hello world’ with typed input and output parameter declarations

packages:
  hello_world_package:
    ... # Package keys omitted for brevity
    actions:
      hello_world_typed_parms:
        function: src/hello_plus.js
        inputs:
          name: string
          place: string
          children: integer
          height: float
        outputs:
          greeting: string
          details: string

where the function ‘hello_plus.js’, within the package-relative subdirectory named ‘src’, is updated to use the new parameters:

function main(params) {
    msg = "Hello, " + params.name + " from " + params.place;
    family = "You have " + params.children + " children ";
    stats = "and are " + params.height + " m. tall.";
    return { greeting:  msg, details: family + stats };
}

Deploying

$ wskdeploy -m docs/examples/manifest_hello_world_typed_parms.yaml

Invoking

$ wsk action invoke hello_world_package/hello_world_typed_parms --blocking

Result

The invocation should return an ‘ok’ with a response that includes this result:

"result": {
  "details": "You have 0 children and are 0 m. tall.",
  "greeting": "Hello,  from "
},

Discussion

In this example:

  • The default value for the ‘string’ type is the empty string (i.e., ""); it was assigned to the ‘name’ and ‘place’ input parameters.
  • The default value for the ‘integer’ type is zero (0); it was assigned to the ‘age’ input parameter.
  • The default value for the ‘float’ type is zero (0.0f); it was assigned to the ‘height’ input parameter.

Source code

The manifest file for this example can be found here:

Specification

For convenience, the Actions and Parameters grammar can be found here: