Skip to content

gravitee-io-community/gravitee-policy-pizza

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pizza Factory policy

Phases

onRequest onResponse onMessageRequest onMessageResponse

X

X

Description

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

Configuration

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, Pan

string

sauce

X

The sauce to use on the crust. Can be TOMATO or SAUCE

string

pineappleForbidden

Is pineapple forbidden. Ends in a 406 - Not Acceptable on request and 500 - Internal Server Error on response if "pineapple" is found in the toppings.

boolean

true

Example configuration:

{
    "configuration": {
        "crust": "Pan",
        "sauce": "TOMATO",
        "pineappleForbidden": false
    }
}

Examples

Using the previous configuration example and for this input:

Payload
[
    "cheddar", "mustard"
]
Headers
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"
  ]
}

Errors

Phase Code Error template key Description

REQUEST

406 - NOT ACCEPTABLE

PIZZA_ERROR

Not Acceptable to have pineapple on a Pizza.

REQUEST

400 - BAD REQUEST

PIZZA_ERROR

The paylaod is not an array of string or an error occurs while processing pizza

RESPONSE

500 - INTERNAL SERVER ERROR

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages