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.

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/

Authorization
Api-Key $TARUVI_API_KEY
Content-Type
application/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"
}
View cURL
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';

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

client is the Client from JavaScript SDK.

Checkpoint. The response's data is:

{"message": "Order 123 received"}

The direct SDK and REST responses include the invocation record beside data. The Refine hook exposes the synchronous return value at mutation.data.data.

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/

Authorization
Api-Key $TARUVI_API_KEY
View cURL
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 while keeping its history, set is_active to false, and set each schedule's is_active to false in the same request: deactivating the function alone doesn't stop its scheduled runs.

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#