sails-hook-actions

Allow Sails to load machines from an `api/actions` folder and load them using machine-as-action


License
MIT
Install
npm install sails-hook-actions@1.1.1

Documentation

sails-hook-actions

Sails JS hook to load files from the api/actions folder and interpret them as machines compatible with machine-as-action.

This hook adds support for the {action: 'some-action'} route target syntax. Traditional controller files (in api/controllers) and controller route target syntax are still supported.

Installation

npm install sails-hook-actions

Usage

requires at least sails >= 0.12

Create an api/actions folder, then add Javascript files (ending in .js) in that folder or in subfolders. The files must be valid node-machine definitions, and may include the additional options described in the machine actions docs (e.g. the responseType property for exits).

To point a route at an action, use the {action: 'some-action-identity'} syntax, for example:

'GET /hi': {action: 'say-hi'}
'POST /user/go': {action: 'useractions/some-user-action'}

where the value of action is the identity of an action (i.e. its filepath relative to api/actions, lowercased and without the .js extension)