---
name: azion-run-a-function-on-an-application
description: >-
  Add the Rules Engine rule that runs a function instance on an application, from Azion Console or the Azion API, then verify the response.
---

# Run a function on an application

A function instance runs only when a [Rules Engine](/en/documentation/platform/applications/rules-engine/) rule selects it with the **Run Function** behavior. You add that rule from Azion Console or the Azion API. For a guided first run that creates the function, the instance, and the rule in one pass, refer to [Functions quickstart](/en/documentation/platform/functions/quickstart/).

---

## Prerequisites

- A function on the account. To write one, refer to [Write and test a function](/en/documentation/guides/application-development/functions-and-runtime/first-steps/).
- A function instance on the application. To create one, refer to [Instantiate a function on an application](/en/documentation/guides/application-development/getting-started/instantiate-functions/).
- The **Application Accelerator** module turned on for the application. The **Run Function** behavior requires it. Refer to [Application Accelerator](/en/documentation/platform/applications/#application-accelerator).
- The **Edit Applications** permission on the account. The rule changes an application. Refer to [Teams Permissions](/en/documentation/fundamentals/teams-permissions/).
- A [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), for the API path.

> **Tip**
>
> A pre-built function from [Azion Marketplace](/en/documentation/platform/marketplace/) replaces a function you write. The **Azion - Hello World** function is linked to your account and is ready to instantiate.

---

## Add the rule that runs the function

The rule sets the execution phase, the criteria that trigger it, and the instance it runs. It then runs that instance on every request that matches the criteria. Azion Console and the Azion API create the same rule.

### Add the rule in Azion Console

To add the rule from Azion Console:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **In the Rules Engine tab, select + Rule**

3. **Name the rule**

   Enter a name for the rule. For example: `Run hello-world`.

4. **Select Request Phase**

5. **In the Criteria section, select the URI variable**

   Select the `${uri}` variable.

6. **Select is equal as the comparison operator**

7. **Enter the URI that runs the function**

   Enter the URI as the argument. For example: `/hello-world`.

8. **In the Behaviors section, select Run Function**

9. **Select the function instance**

10. **Select Save**

The rule appears in the **Rules Engine** tab of the application. New rules can take a few minutes to propagate.

> **Note**
>
> If **Run Function** is not in the **Behaviors** list, the application also needs the **Application Accelerator** module. Refer to [Run Function is missing from the behaviors list](/en/documentation/platform/functions/troubleshooting/#run-function-is-missing-from-the-behaviors-list) for the fix.

### Add the rule with the Azion API

Send a `POST` request to the request rules endpoint of the application. Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `<application_id>` with [your application ID](/en/documentation/guides/application-development/getting-started/configure-main-settings/), and `<edge_function_instance_id>` with the ID of the function instance:

```bash
curl --request POST \
  --url https://api.azion.com/v4/workspace/applications/<application_id>/request_rules \
  --header 'Accept: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "Run Hello World",
  "active": true,
  "criteria": [
    [
      {
        "conditional": "if",
        "variable": "${uri}",
        "operator": "is_equal",
        "argument": "/hello-world"
      }
    ]
  ],
  "behaviors": [
    {
      "type": "run_function",
      "attributes": { "value": <edge_function_instance_id> }
    }
  ],
  "description": "Run function on /hello-world"
}'
```

The response returns the rule the application now carries:

```json
{
  "state": "pending",
  "data": {
    "id": <rule_id>,
    "name": "Run Hello World",
    "active": true,
    "criteria": [
      [
        {
          "conditional": "if",
          "variable": "${uri}",
          "operator": "is_equal",
          "argument": "/hello-world"
        }
      ]
    ],
    "behaviors": [
      {
        "type": "run_function",
        "attributes": {
          "value": <edge_function_instance_id>
        }
      }
    ],
    "description": "Run function on /hello-world",
    "order": 0,
    "last_editor": "your-email@example.com",
    "last_modified": "2026-01-01T12:00:00.000000Z"
  }
}
```

The `"state": "pending"` value means the rule takes a few minutes to propagate. For every field of the rules endpoint, refer to [Create an application rule](/en/documentation/guides/application-development/getting-started/work-with-rules-engine/).

---

## Verify the response

Your application answers on a domain in the format `xxxxxxxxx.map.azionedge.net`. To set the domain for your application, refer to [Add a custom domain to a workload](/en/documentation/guides/platform/migration/configure-a-domain/).

Wait for the rule to propagate, then request the URI set in the criteria:

```bash
curl https://<your-azion-domain>/hello-world
```

The response body is the string the function returns. The `hello-world` function of the [Functions quickstart](/en/documentation/platform/functions/quickstart/) answers:

```
Hello World!
```

A response that does not come from the function means the rule did not match the request, or the change has not propagated yet.

---

## Next steps

- [Functions quickstart](/en/documentation/platform/functions/quickstart.md): The full path, from an empty account to a function that answers a request.
- [Instantiate a function on an application](/en/documentation/guides/application-development/getting-started/instantiate-functions.md): Create the instance this rule selects, and pass its Args in JSON.
- [Create an application rule](/en/documentation/guides/application-development/getting-started/work-with-rules-engine.md): The criteria and behaviors a rule carries, beyond Run Function.
- [Troubleshoot function execution and logs](/en/documentation/platform/functions/troubleshooting.md): What to check when a function does not run, or returns an error.
