Rules
The azion/applications functions that create, list, read, update, and delete the rules of an application phase.
A rule belongs to the Rules Engine of an application, in the request phase or the response phase. These azion/applications functions create, list, read, update, and delete those rules, and each one takes the phase as phase.
createRule
Creates a rule of the Rules Engine of an application, in the request phase or the response phase.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId | number | Yes | The ID of the application. |
phase | 'request' | 'response' | Yes | The phase the rule runs in. |
data | ApiCreateRulePayload | Yes | The rule: name, phase, criteria, and behaviors. |
options | AzionClientOptions | No | Request options. |
criteria is a list of condition groups, and each group is a list of conditions with variable, operator, conditional, and input_value. behaviors lists the actions, each with a name and a target. For the variables, operators, and behavior names a rule can use, refer to Rules Engine for Applications.
Returns data as the created AzionRule, with its id and order. In the sample, as const keeps the literal types that phase and conditional need in TypeScript.
Output:
getRules
Lists the rules of one phase of an application, one page at a time.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId | number | Yes | The ID of the application. |
phase | 'request' | 'response' | Yes | The phase to list. |
params | ApiListRulesParams | No | Pagination: page and page_size. |
options | AzionClientOptions | No | Request options. |
Returns an AzionApplicationCollectionResponse whose data.results holds AzionRule objects. The request list also holds Default Rule, the rule in phase default that a new application already has.
Output:
getRule
Returns one rule of an application by its phase and ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId | number | Yes | The ID of the application. |
phase | 'request' | 'response' | Yes | The phase of the rule. |
ruleId | number | Yes | The ID of the rule. |
options | AzionClientOptions | No | Request options. |
Returns data as an AzionRule.
Output:
updateRule
Sends the rule fields you pass in a PATCH request. Fields you leave out keep their values: a call that does not send criteria leaves the criteria of the rule unchanged.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId | number | Yes | The ID of the application. |
phase | 'request' | 'response' | Yes | The phase of the rule. |
ruleId | number | Yes | The ID of the rule to update. |
data | ApiUpdateRulePayload | Yes | The fields to change. Every field is optional. |
options | AzionClientOptions | No | Request options. |
Returns data as the updated AzionRule.
Output:
deleteRule
Deletes a rule of an application by its phase and ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationId | number | Yes | The ID of the application. |
phase | 'request' | 'response' | Yes | The phase of the rule. |
ruleId | number | Yes | The ID of the rule to delete. |
options | AzionClientOptions | No | Request options. |
A successful delete returns error with the message Expected JSON response, but got: , so the sample reads the rule back with getRule. A 404 error confirms the delete.
Output: