# Policy Param
The policy param is a good way to carry some additional application configurations that can be reused either in the policy itself or fetched in the code. What is great about policy params is that they also can be conditional like statements.
For example, you may want to define different API endpoints based on the application environment. So this can be accomplished with a policy like this:
{
"Param": [
{
"Key": "API:endpoint",
"Value": "https://staging-myapi.mydomain.io",
"Condition": {
"Equals": {
"${ENV.type}": "staging"
}
}
},
{
"Key": "API:endpoint",
"Value": "https://myapi.mydomain.io",
"Condition": {
"Equals": {
"${ENV.type}": "production"
}
}
}
]
}
Now the only thing that your application environment needs to have is the type
environment variable. The rest is taken care of and you can fetch the API:endpoint
param in your code without any overheads.
FYI! To learn more about fetching policy params programmatically, please refer to the respective language library reference page.
# Key
- Type:
String
- Required
The Key
attribute has to contain a scalar value, typically string. There is no limit on how long the string can be and it is up to your discretion to name the param in a meaningful way. The only recommendation here is to stay consistent with naming and formatting patterns.
# Value
- Type:
Any
- Required
The Value
attribute may contain any sort of information. It can be a scalar value or an object. JSON policy does not enforce any constraints on what it may contain.
In the example below, you'll find params that contain a simple string and complex JSON structure and both are valid.
{
"Param": [
{
"Key": "my-string",
"Value": "Hello World!"
},
{
"Key": "my-object",
"Value": {
"top-level": {
"phrase": "Hello World!"
}
}
},
]
}
# Enforce
- Type:
Boolean
- Optional
The Enforce
is an optional attribute that enforces certain param over other params with exactly the same Key
name. It works exactly the same way as the Enforce
attribute for the statements and you can refer to its description to learn a bit more.
# Condition
- Type:
{ Equals: Object, NotEquals: Object, ... }: Object
- Optional
The Condition
attribute is the optional attribute and contains a collection of conditions that if meat, classify the param as applicable. This is a good way to determine if the param is applicable within the current executable context.
Note! Conditions are discussed in greater details in the "Policy Condition" section.