Actions
Defining actions is a way to organize which APIs are exposed and how they are used within an application or platform.
Properly defining actions can assist with the following:
- Service discovery
- Documentation
- Operational insight
Services MUST list actions that can be executed.
At a high level, services SHOULD define the following about themselves:
- Interface (HTTP/RPC/etc)
- Arguments
- Output
Example
Here's an action called convert which accepts units, from and to returning an object with two properties - units and currency.
actions:
convert:
help: Convert a currency into another currency
http: # defining how to execute this action, more below
arguments:
units:
type: number
from:
type: string
to:
type: string
output:
type: object
properties:
units:
type: number
currency:
type: string
Overview
Within a named action, the following fields are available:
| Field | Description |
|---|---|
help | Required. A human friendly description for this action |
arguments | Optional and required inputs the action has. Read more |
output | Required. Type of data that the action returns. Read more |
http | rpc | format | Required. How to call the action. Read more |
Arguments
actions.$.arguments actions.$.events.$.argumentsDefine the arguments (input data) that the action accepts.
An action MUST declare all arguments it accepts. Each argument, will have the following information about it:
| Field | Description |
|---|---|
help | A short description of the argument which can provide clarity to end user |
type | Required. The type of this argument. It must be one of int, float, string, list, map, boolean, enum, or any |
in | Required. The location of this argument. Each execution strategy provides different possible values for this. Possible values are requestBody, query, and path. (Required for http interface) |
required | Whether this argument is required or not. The default value for this is false |
default | The default value if not provided by the user (not available for types map or object) |
pattern | Read more (for type: string only) |
enum | Read more (for type: enum only) |
range | Read more (for type: int|float only) |
Example
Here is an action called capitalize which accepts string and returns a string.
actions:
capitalize:
arguments:
text:
help: The string to capitalize.
type: string
in: requestBody
http:
method: post
port: 8000
path: /run/capitalize
contentType: application/json
output:
type: string
$ curl -H "Content-Type: application/json" -d '{"text":"einstein"}' http://service:8000/run/capitalize
# Einstein
Patterns
actions.$.arguments.$.pattern actions.$.events.$.arguments.$.patternThe argument color must match the regexp pattern.
actions:
colorize:
arguments:
color:
type: string
pattern: '^\#?\w{6}$'
Enums
actions.$.arguments.$.enum actions.$.events.$.arguments.$.enumThe argument color must match one of the values under enum.
actions:
colorize:
arguments:
color:
type: enum
enum:
- red
- blue
- green
Range
actions.$.arguments.$.range actions.$.events.$.arguments.$.rangeThe argument threshold must be within a range.
actions:
colorize:
arguments:
threshold:
type: int
range: # default is no bounds for min and max
min: 10
max: 20
Output
actions.$.arguments.$.output actions.$.events.$.arguments.$.outputOutputs are what the action returns as its result.
An action MUST define it's output.
| Field | Description |
|---|---|
type | The type of output. It must be one of int, float, string, list, map, boolean, object, or any |
contentType | If the type is specified as object, this MUST indicate the Content-Type of the response |
properties | A map of key: {Output} (only for map or object types) |
actions | A map of action: {Action} that can be performed by this output (only for object types) |
If there is no output then it must use
output: nullexplicitly.
Properties
actions.$.arguments.$.output.properties actions.$.events.$.arguments.$.output.propertiesA map of properties this object has defined.
actions:
getAddress:
...
output:
type: object
properties:
lat:
type: float
long:
type: float
The output of this action returns an object that has two properties that can be accessed: lat and long.
Next Actions
actions.$.arguments.$.output.actions actions.$.events.$.arguments.$.output.actionsAn output MAY define other actions the user may perform.
The action may reference properties of its parent.
actions:
like: &like
arguments:
tweetid:
type: int
output: null
stream:
events:
tweet:
output:
properties:
id:
type: int
actions:
like:
<<: *like # yaml feature to reuse a defined structure (see &like above)
defaults:
tweetid: id
Twitter streams tweets. Each tweet has an output of which has an action
like. It utilizes the service's actionlikeby setting the argumenttweetidto the propertyid. See full example here.