Skip to content

Easy Actions Work in Progress!

Actions are the way you define how your app can be interacted with.

Action Definition

PropertyTypeDescription
actionNamestringThe name of the action. It's used as the key to identify the action
descriptionstringA short description of what the action does.
actionfunctionThe function that is called when the action is triggered.
paramsobjectis an object that describes the parameters that the action takes.
responsestringis 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:

ParameterDescription
groupThe name of the group that the action belongs to.
actionThe 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.

http://localhost:8000/api

If you go to the group endpoint, you'll see a list of all the actions in that group.

http://localhost:8000/api?group=app

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

typescript
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:

json
{
  "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.

With Parameters

Released under the MIT License.