You can use the pizza
policy to create a pizza from request or response headers and/or body.
This policy allows the API Publisher to configure:
* The crust
, which can be any string
* The sauce
, which can only be TOMATO
or CREAM
* If he allows the API Consumer to add pineapple
or 🍍
topping on its pizza.
Then, the consumer of the API has to provide toppings to build the pizza.
It can be done by providing one of the following or both:
* X-Pizza-Topping
header with as many value as he wants
* An array of strings as a json payload. Providing an invalid payload will result on a 400 - BAD_REQUEST
or 500 - Internal Server Error
If no toppings are provided, the policy does nothing expect adding the X-Pizza: not-created
header.
Else, a pizza object will be created and set as payload, and the header X-Pizza: created will be added
.
If pineapple
is forbidden, and the API COnsumer tries to use it as a topping, then it should result in
* A 406 - Not Acceptable
on the request phase
* A 500 - Internal Server Error
on the response phase
You can configure the policy with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
crust |
X |
The crust to use for your pizza, for example, |
string |
|
sauce |
X |
The sauce to use on the crust. Can be |
string |
|
pineappleForbidden |
Is pineapple forbidden. Ends in a |
boolean |
|
Example configuration:
{
"configuration": {
"crust": "Pan",
"sauce": "TOMATO",
"pineappleForbidden": false
}
}
Using the previous configuration example and for this input:
[
"cheddar", "mustard"
]
X-Pizza-Topping: mushroom
X-Pizza-Topping: onions
X-Pizza-Topping: ham
The output is as follows:
{
"crust": "Pan",
"sauce": "TOMATO",
"toppings": [
"cheddar",
"mustard",
"mushroom",
"onions",
"ham"
]
}
Phase | Code | Error template key | Description |
---|---|---|---|
REQUEST |
|
PIZZA_ERROR |
Not Acceptable to have pineapple on a Pizza. |
REQUEST |
|
PIZZA_ERROR |
The paylaod is not an array of string or an error occurs while processing pizza |
RESPONSE |
|
PIZZA_ERROR |
Not Acceptable to have pineapple on a Pizza or the paylaod is not an array of string or an error occurs while processing pizza |