The flow describes how the incoming request from the client is transformed into the outgoing response. The flow comprises actions, control structures and variables.
Each endpoint of your API can have its individual flow specified by x-flat-flow
, see Routing.
Here we have a flow with if-elseif-else
conditional statements and some echo
actions evaluating the $request
variable:
<flow>
<if test="$request/query = 42">
<echo>Yeah, that's it!</echo>
</if>
<elseif test="$request/query">
<echo>Um, no!</echo>
</elseif>
<else>
<echo>Do you know the answer?</echo>
</else>
</flow>
break
stops the flow processing for the current request. It may be used in
sub flows or the init flow, too.
Response processing (such as validation and sending out the response) will continue, though.
A break
statement should usually be executed conditionally, because otherwise
none of the following statements will ever be executed.
<flow>
<break/>
<echo>will never be reached</echo>
</flow>
See also:
The if
statement and the optional elseif
and else
statements allow for conditional execution of flow blocks.
<flow>
<if test="…">…</if>
<if test="…">…</if>
<else>…</else>
<if test="…">…</if>
<elseif test="…">…</elseif>
<if test="…">…</if>
<elseif test="…">…</elseif>
<elseif test="…">…</elseif>
<else>…</else>
</flow>
Conditional expressions are defined in the test="…"
attributes of the if
and elseif
statements.
If such an expression evaluates to true
, the flow block inside that if
(or elseif
) will be executed. All directly following elseif
and else
blocks will then be skipped.
If the result of that expression is false
, the block will be skipped and the condition of the following elseif
statement will be checked, if applicable.
The block associated with the first matching conditional expression will be executed – or if all expressions were evaluated to false
, the else
block will be executed.
return
quits the current sub flow and returns to its parent flow.
If return
is used in the init flow the regular API path flow will still be executed.
A return
statement on the top-most flow behaves like break
.