Skip to main content

Create, run, and delete a function

Create one app-mode function that needs no data, no schedule, and no external service, run it, then remove it. You can do every step in TaruviBase Console or with the REST API; the SDKs can only run a function that already exists.

Before you begin​

You need:

  • An app in a development site, and its slug.
  • An organization owner or admin account, or another cloud user with access to the site.
  • An authenticated interface: TaruviBase Console, or the environment prepared in Create your first task for the REST and SDK steps.

No data table, secret, schedule, or external service is required.

1. Create the function​

Create an app-mode function that returns a message built from its input.

POST/api/apps/$TARUVI_APP_SLUG/functions/
curl -X POST "$TARUVI_SITE_URL/api/apps/$TARUVI_APP_SLUG/functions/" \
-H "Authorization: Api-Key $TARUVI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<'JSON'
{
"name": "Greet order",
"execution_mode": "app",
"description": "Return a greeting for an order.",
"code": "def main(params, user_data, sdk_client):\n return {\"message\": \"Order %s received\" % params.get(\"order_id\")}\n"
}
JSON

201Returns the created function, including its generated slug.

Checkpoint. The function now exists in the app's function list, with a generated slug — most likely greet-order. That slug identifies it from here on, and the REST examples below refer to it as FUNCTION_SLUG.

Copy the def main(params, user_data, sdk_client): line exactly. It is checked as literal text, so annotations and renamed parameters are rejected. See the function signature.

2. Run the function​

import {Functions} from '@taruvi/sdk';

const result = await new Functions(client).execute('greet-order', {
params: {order_id: 123},
});

client is the Client from JavaScript SDK.

Checkpoint. The function returns:

{"message": "Order 123 received"}

The run is also recorded, with a task id alongside the result. That record is what you read later to see what a run received, returned, and logged.

3. Delete the function​

Delete the function when you are finished experimenting.

DELETE/api/apps/$TARUVI_APP_SLUG/functions/$FUNCTION_SLUG/
curl -X DELETE "$TARUVI_SITE_URL/api/apps/$TARUVI_APP_SLUG/functions/$FUNCTION_SLUG/" \
-H "Authorization: Api-Key $TARUVI_API_KEY"

204Returns no body. Invocation records, schedules, and version history are deleted with the function.

Deleting a function is permanent

Deleting removes the function together with its version history, its invocation records, and any schedules attached to it. Nothing is recoverable, and there is no disabled state to fall back on afterwards. To stop a function running while keeping its history, set is_active to false instead.

Checkpoint. The function no longer appears in the app's function list, and its version history and past runs are gone with it.

You created, ran, and removed a function​

Versions, schedules, webhook forwarding, and event triggers all build on this same function with more configuration.

Next steps​