π¬ Action Processor
Action Processor is a powerful tool to let sentio users write custom logic to process data. It is a serverless function that can be triggered by calling sentio endpoints.
How to create an Action Processor
To create an Action Processor, you can simply run the following command to create a sentio processor project.
npx @sentio/cli@latest create `<project name>`
The commands will generate a template project, then open the project in your favorite code editor. Edit the sentio.yaml
, change the type
to action
.
project: your-project-name
host: https://app.sentio.xyz
type: action
If you don't need other functions provides by @sentio/sdk
, you can also edit the package.json
file, change the @sentio/sdk
to @sentio/action
from the dependencies. This reduces the size of the dependency package.
"dependencies": {
"@sentio/action": "<the same as the sdk version>"
}
How to write an Action Processor
Clean the src/processor.ts
file and write your custom logic. Here is an example of a simple Action Processor that logs the data.
import { ActionProcessor, ActionRequest } from '@sentio/action'
ActionProcessor.bind()
.onGet('/hello/:name', async (request: ActionRequest, context: any) => {
const { name } = request.params
return `Hello, ${name}!`
})
Other than the onGet
method, you can also use onPost
, onPut
, onDelete
to handle different HTTP methods, and you can also use onAll
to handle all methods.
For the request object, you will have the following properties:
params
: the parameters in the URLmethod
: the HTTP methodheaders
: the HTTP headersbody
: the request bodyurl
: the request URLquery
: the query parameters
How to access the Action Processor
After you have written your custom logic, you can build and upload the processor project by using the following command
yarn sentio upload
When the processor is up and running, you can access it by calling the sentio endpoint. Go to the your project page, click on the Endpoint menu on the left sidebar. You will see the endpoints, you can use it to access the Action Processor.
More features are coming soon
Ask sentio team for more features you want to see in Action Processor. We are always happy to help you with your custom logic.
Updated 1 day ago