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.
- REST API
- TaruviBase Console
/api/apps/$TARUVI_APP_SLUG/functions/Headers
AuthorizationApi-Key $TARUVI_API_KEYContent-Typeapplication/json
Request body
{
"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.
- Open the app and select Functions.
- Select Create Function, then choose the APP execution mode.
- Name it
Greet order. - Paste the code below into the Editor tab, then save.
def main(params, user_data, sdk_client):
return {"message": "Order %s received" % params.get("order_id")}
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#
- JavaScript SDK
- Python SDK
- Refine
- REST API
- TaruviBase Console
import {Functions} from '@taruvi/sdk';
await new Functions(client).execute('greet-order', {
params: {order_id: 123},
});
client is the Client from JavaScript SDK.
client.functions.execute(
"greet-order",
params={"order_id": 123},
)
Configure the named app provider using Refine setup.
import {useCustomMutation} from '@refinedev/core';
const {mutate: run} = useCustomMutation();
// Call from an event handler.
run({
dataProviderName: 'app',
url: 'greet-order',
method: 'post',
values: {order_id: 123},
meta: {kind: 'function', async: false},
});
The hook exposes the function's return value at mutation.data.data.
/api/apps/$TARUVI_APP_SLUG/functions/$FUNCTION_SLUG/execute/Headers
AuthorizationApi-Key $TARUVI_API_KEYContent-Typeapplication/json
Request body
{
"params": {
"order_id": 123
},
"async": false
}
View cURL
curl -X POST "$TARUVI_SITE_URL/api/apps/$TARUVI_APP_SLUG/functions/$FUNCTION_SLUG/execute/" \
-H "Authorization: Api-Key $TARUVI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<'JSON'
{
"params": {
"order_id": 123
},
"async": false
}
JSON
200Returns the function's return value in data, with the invocation record alongside it.
- Open the function and select the Editor tab.
- Enter
{"order_id": 123}in the Params panel. - Run the function with
Cmd/Ctrl+Enter, then read the Result panel.
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.
- REST API
- TaruviBase Console
/api/apps/$TARUVI_APP_SLUG/functions/$FUNCTION_SLUG/Headers
AuthorizationApi-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.
- Open the function.
- Delete it, and confirm.
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#
- Write a function — the SDK client, error handling, and versions
- Execute a function — asynchronous execution and reading results
- Read logs and invocations — what each run recorded
- Security and limits — before you make anything public