Easy Actions Work in Progress!
Actions are the way you define how your app can be interacted with.
Action Definition
Property | Type | Description |
---|---|---|
actionName | string | The name of the action. It's used as the key to identify the action |
description | string | A short description of what the action does. |
action | function | The function that is called when the action is triggered. |
params | object | is an object that describes the parameters that the action takes. |
response | string | is a string representing the type of the response. |
Actions are grouped together in groups
.
groupName
is the name of the group.
There are two built-in groups that come with Easy App: app
and entity
, but more on that later.
API
Your actions will be available at the /api
endpoint along with the built-in actions.
The /api
endpoint takes two parameters:
Parameter | Description |
---|---|
group | The name of the group that the action belongs to. |
action | The name of the action. |
The api will return a JSON object with the response from the action.
For example, there's an action called status
in the app
group. The endpoint for this action would look like this:
http://localhost:8000/api?group=app&action=status
For your convenience
In the world of VEF
there's a focus on making the information you may need available where and when you need it during development.
As such, the API is designed to be self-documenting. If you visit the /api
endpoint in your browser, you'll see a list of all the available groups and their actions.
If you go to the group endpoint, you'll see a list of all the actions in that group.
Creating Actions
This section will cover how to create actions.
Note
The function that assign to the action
property of the action definition will be passed the app
object as its first argument.
This is the app
object that you created when you instantiated the EasyApp
class.
Simple Example
Let's start with a simple example. We'll create an action that says hello to
import { createAction, EasyApp } from "@vef/easy-app";
const app = new EasyApp();
const action = createAction("myAction", {
description: "This is my action",
action: (app) => {
return "I have acted!";
},
});
app.addAction("app", action);
Now you can visit http://localhost:8000/api?group=app&action=myAction to see your action in action.
The response will be:
{
"message": "I have acted!"
}
Note
When you return a string from an action, it will be wrapped in a JSON object with the key message
.