Function
Introducation
The Function Element is used to handle business logic. You can customize the input parameters and return value types. A good design principle is to ensure that the code logic of a Function Element is consistent with its name and behavior.
Access
Access in the HTTP Element
Suppose there is a Function Element named "myFunc". Its code is as follows:
export default async function (name: string) {
return `hello ${name}`;
}
In the HTTP Element or other Elements that support coding, you can access the "myFunc" Function Element in the following way:
import * as Koa from "koa";
import { myFunc } from "#elements";
export default async function (request: Koa.Request, response: Koa.Response, ctx: Koa.Context) {
return myFunc(request.params.name)
}
Access in the Executor
In development or debugging scenarios, you can use the Function Executor to directly trigger the Function Element. You can pass parameters when triggering, and you can view the details of code execution after triggering.