How to create rules to automate behaviors with Rules Engine

Implementing rules in your application using Rules Engine will allow you to determine the tasks it should execute in specific scenarios without modifying your application’s code.

This guide demonstrates the process of creating rules with a practical example, but most rules will be unique to each application and its needs. In addition to activating variables such as device groups, cache settings, and origins, you can create a wide variety of rules in both the request and response phases.

With this guide, you’ll create a rule in the response phase to remove an HTTP header using the Filter Response Header behavior.


To activate the Application Accelerator module:

  1. Access Azion Console.
  2. On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and select Edge Application.
  3. Click the edge application you want to configure.
  4. Activate the Application Accelerator module.
  5. Click the Save button.

The Server header stores information about the server that generated the response. By removing this header, end-users won’t receive information about the infrastructure of your application, enhancing your security by reducing the information available to potential attackers.

To remove the Server header:

  1. Navigate to the Rules Engine tab.
  2. Click the Add Rule button.
  3. On the dropdown menu, select Response Phase.
  4. Give your rule a name and, if necessary, a description.
  5. In the Criteria section, select the ${uri} variable.
  6. As a comparison operator, select starts with.
  7. As an argument, add the value /.
  8. In the Behaviors section, select Filter Response Header.
  9. As an argument, add Server.
  10. Click the Save button.

  1. Run the following PATCH request in your terminal, replacing [TOKEN VALUE] with your personal token and the <edge_application_id> variable with your edge application ID to activate the Application Accelerator module:
Terminal window
curl --location --request PATCH 'https://api.azionapi.net/edge_applications/<edge_application_id>' \
--header 'Accept: application/json; version=3' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
"application_acceleration": true
}'
  1. You’ll receive a response with the updated value.
  2. Run the following POST request to create a rule in the response phase, replacing <edge_application_id> with the id value you received in the previous response:
Terminal window
curl --location 'https://api.azionapi.net/edge_applications/<edge_application_id>/rules_engine/response/rules' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"name": "FilterRespHeader Server",
"behaviors": [
{
"name": "filter_response_header",
"target": "Server"
}
],
"criteria": [
[
{
"variable": "${uri}",
"operator": "is_equal",
"conditional": "if",
"input_value": "/"
}
]
]
}'
  1. You’ll receive the following response:
{
"results": {
"id": <rule_id>,
"name": "FilterRespHeader Server",
"phase": "response",
"behaviors": [
{
"name": "filter_response_header",
"target": "Server"
}
],
"criteria": [
[
{
"variable": "${uri}",
"operator": "is_equal",
"conditional": "if",
"input_value": "/"
}
]
],
"is_active": true,
"order": 1,
"description": null
}
}
  1. Wait a few minutes for the changes to propagate.

Contributors