Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Action

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.

```js import { Action } from "actionhero";

export default class RandomNumber extends 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 ({ response }) { response.randomNumber = Math.random() } }


Hierarchy

  • Action

Index

Constructors

constructor

Properties

Optional blockedConnectionTypes

blockedConnectionTypes: string[]

Are there connections from any servers which cannot use this Action (default: [])?

description

description: string

The description of the Action (default this.name)

Optional inputs

inputs: Inputs

The inputs of the Action (default: {})

Optional logLevel

logLevel: string

Under what level should connections to this Action be logged (default 'info')?

Optional matchExtensionMimeType

matchExtensionMimeType: boolean

If this Action is responding to a web request, and that request has a file extension like *.jpg, should Actionhero set the response headers to match that extension (default: true)?

Optional middleware

middleware: string[]

The Middleware specific to this Action (default: []). Middleware is described by the string names of the middleware.

name

name: string

The name of the Action

Optional outputExample

outputExample: object

Optional toDocument

toDocument: boolean

Should this Action appear in api.documentation.documentation? (default: true)?

Optional version

version: string | number

The version of this Action (default: 1)

Methods

Private defaults

  • defaults(): { blockedConnectionTypes: any[]; description: string; inputs: {}; logLevel: string; matchExtensionMimeType: boolean; middleware: any[]; name: any; outputExample: {}; toDocument: boolean; version: number }
  • Returns { blockedConnectionTypes: any[]; description: string; inputs: {}; logLevel: string; matchExtensionMimeType: boolean; middleware: any[]; name: any; outputExample: {}; toDocument: boolean; version: number }

    • blockedConnectionTypes: any[]
    • description: string
    • inputs: {}
    • logLevel: string
    • matchExtensionMimeType: boolean
    • middleware: any[]
    • name: any
    • outputExample: {}
    • toDocument: boolean
    • version: number

Abstract run

  • run(data: {}): Promise<ActionResponse>
  • 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

    • data: {}

      The data about this connection, response, and params.

      • [key: string]: any

    Returns Promise<ActionResponse>

validate

  • validate(): void

Generated using TypeDoc