new Action()
- Source:
- Tutorials:
Properties:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the Action. |
description |
string | The description of the Action (default this.name). |
version |
Number | The version of this Action (default: 1). |
outputExample |
Object | An example response payload (default: {}). |
inputs |
Object | The inputs of the Action (default: {}). |
middleware |
Array | The Middleware specifit to this Action (default: []). Middleware is descibed by the string names of the middleware. |
blockedConnectionTypes |
Array | Are there connections from any servers which cannot use this Action (default: [])? |
logLevel |
string | Under what level should connections to this Action be logged (default 'info')? |
matchExtensionMimeType |
Boolean | If this Action is responding to a |
toDocument |
Boolean | Should this Action appear in api.documenation.documenation? (default: true)? |
Create a new ActionHero Action. The required properties of an action. These can be defined statically (this.name) or as methods which return a value.
Example
'use strict'
const ActionHero = require('actionhero')
module.exports = class RandomNumber extends ActionHero.Action {
constructor () {
super()
this.name = 'randomNumber'
this.description = 'I am an API method which will generate a random number'
this.outputExample = {randomNumber: 0.1234}
}
async run (data) {
data.response.randomNumber = Math.random()
}
}
Methods
(async, static) run(data)
- Source:
The main "do something" method for this action. It can be async. Usually the goal of this run method is to set properties on data.response. If error is thrown in this method, it will be logged, caught, and appended to data.response.error
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | The data about this connection, response, and params. |