Writing switch condition scripts - DataPower Gateway (v5 compatible)
You write condition scripts for the
switch policy in the DataPower® Gateway (v5
compatible) by using
To reference variables in your
switch conditions, use the form
where context is the context that you want to reference,
location is the location of the variable within that context, and
variable is the name of the variable.
to define a
switchcondition based on the operation called, use one of the following forms:
- condition: "((request.verb==='GET')&&(api.operation.path==='/path-1'))"
where the context variables
- condition: "((api.operation.id=='Operation_ID'))"
api.operation.pathretrieve the HTTP verb and the path segment of the API and operation that you want your case to apply to, while
api.operation.idretrieves the operation ID of your operation, if one has been specified.
For information about the context variables you can use and how to reference them in your script, see API Connect context variables.
Example switch policy
- switch: version: 1.0.0 title: switch case: - condition: message.status.code===200 execute: - invoke: title: invoke timeout: 60 verb: GET cache-response: protocol cache-ttl: 900 target-url: 'https://example.com/1' - condition: ((request.verb==='GET')&&(api.operation.path==='/path-2'))||((request.verb==='GET')&&(api.operation.path==='/path-1')) execute: - invoke: title: invoke timeout: 60 verb: GET cache-response: protocol cache-ttl: 900 target-url: 'https://example.com/2' - otherwise: - set-variable: title: set-variable actions: - set: message.body value: Default result description: Set the default result for the otherwise case