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.
Create a rule
createRule creates a rule of the Rules Engine of an application, in the request phase or the response phase.
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:
The signature of createRule:
Parameters
| 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. |
Get rules
getRules lists the rules of one phase of an application, one page at a time.
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:
The signature of getRules:
Parameters
| 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. |
Get a rule
getRule returns one rule of an application by its phase and ID.
Returns data as an AzionRule.
Output:
The signature of getRule:
Parameters
| 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. |
Update a rule
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.
Returns data as the updated AzionRule.
Output:
The signature of updateRule:
Parameters
| 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. |
Delete a rule
deleteRule deletes a rule of an application by its phase and ID.
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:
The signature of deleteRule:
Parameters
| 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. |