本頁適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
本節提供您用來定義 API 代理程流的 XML 元素參考資訊。
階層與語法
以下範例說明流程設定元素的元素階層和語法:
元素階層
以下範例說明 <ProxyEndpoint>
和 <TargetEndpoint>
元素內的流程設定元素階層:
<ProxyEndpoint | TargetEndpoint><PreFlow>
<Request>
<Step>
<Condition>
<Name>
<Response>
<Step>
<Condition>
<Name>
<Description>
<Flows>
<Flow>
<Description>
<Condition>
<Request>
<Step>
<Response>
<Step>
<Description>
<PostFlow>
<Request>
<Step>
<Response>
<Step>
<Description>
EventFlow<Response>
<Step>
<Description>
<PostClientFlow>
(<ProxyEndpoint> only)<Response>
<Description>
// Additional configuration elements </ProxyEndpoint | TargetEndpoint>
語法
以下範例顯示流程設定元素的語法。以下各節將詳細說明這些元素:
<!-- ProxyEndpoint flow configuration file --> <ProxyEndpoint ... > ... <PreFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PreFlow> <Flows name="flow_name"> <Flow name="conditional_flow_name"> <Description>flow_description</Description> <Condition>property operator "value"</Condition> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </Flow> </Flows> <PostFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PostFlow> <PostClientFlow name="flow_name"> <Description>flow_description</Description> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PostClientFlow> ... </ProxyEndpoint> <!-- TargetEndpoint flow configuration file --> <TargetEndpoint ... > ... <PreFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PreFlow> <Flows name="flow_name"> <Flow name="conditional_flow_name"> <Description>flow_description</Description> <Condition>property operator "value"</Condition> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </Flow> ... </Flows> <PostFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PostFlow> ... </TargetEndpoint>
您可以使用這些元素定義 PreFlow、ConditionalFlow、PostFlow、EventFlow 和 PostClientFlow 執行作業。
<Condition>
定義在執行階段處理的陳述式。如果陳述式評估為 true,就會執行與條件相關聯的步驟或流程。如果陳述式評估為 false,系統會忽略步驟或流程。
類型 | 字串 |
父項元素 |
<Flow> <Step> |
子元素 | 無 |
您可以將條件套用至特定步驟或整個流程,這取決於您將元素放入 <Flow>
或 <Step>
元素:
// Condition can apply to just one step: // Or to the flow:<Flows>
<Flows>
<Flow>
<Flow>
<Step>
<Condition>
<Condition>
<Step>
<Name>
<Name>
... ... ... ... ... ... </Flows> </Flows>
如果 <Step>
中的條件評估結果為 true,Apigee 就會執行該步驟。如果條件評估為 false,Apigee 會略過該步驟。
如果 <Flow>
中的條件評估為 true,Apigee 就會處理流程中的所有步驟。如果條件評估結果為 false,Apigee 會略過整個流程。
語法
<Condition>
元素使用以下語法:
<Condition>property operator "value"</Condition>
其中:
- property
- 您要在條件中使用的流程變數屬性。舉例來說,
request
流程變數具有名為path
和content
的屬性。如要在條件中使用這些值,請指定 flow_variable[dot]property_name:request.path request.content
如需流程變數及其屬性的完整清單,請參閱流程變數參考資料。
- operator
- 定義評估條件的結構。常見的運算子包括:
> greater than <= less than or equal to < less than >= greater than or equal to = equals && and != not equals || or ~~ JavaRegex ~ Matches /~ MatchesPath
如需完整清單,請參閱「條件」參考資料中的「運算子」。
- 「value」
- 用來評估流程變數屬性的值。這通常是基本類型,例如整數或字串。例如
200
或/cat
。這個值可包含萬用字元,例如用於模式比對的星號和其他字元,詳情請參閱「使用條件進行模式比對」一文。
範例 1
以下範例會檢查 request
流程變數的 verb
屬性是否為 GET
:
<!-- api-platform/reference/examples/flow-segments/condition-1.xml --> <ProxyEndpoint name="default"> <PreFlow name="my-preFlows"> <Description>My first PreFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> </PreFlow> ... </ProxyEndpoint>
如果要求是 GET
,則此範例會執行 Log-Request-OK
政策。
範例 2
以下範例會檢查回應代碼:
<!-- api-platform/reference/examples/flow-segments/condition-2.xml --> <ProxyEndpoint name="default"> <PreFlow name="my-preFlows"> <Description>My first PreFlow</Description> <Response> <Step> <Condition>response.status.code LesserThanOrEquals 300</Condition> <Name>Log-Response-OK</Name> </Step> <Step> <Condition>response.status.code GreaterThan 300</Condition> <Name>Log-Response-NOT-OK</Name> </Step> </Response> </PreFlow> ... </ProxyEndpoint>
系統會根據程式碼的值執行不同的政策。
屬性
<Condition>
元素沒有屬性。
子元素
<Condition>
元素沒有子元素。
<Description>
以人類可讀的用語說明流程。使用這個元素,向您或其他開發人員提供流程相關資訊。說明不會向外部顯示。
類型 | 字串 |
父項元素 |
<Flow> <PreFlow> <PostFlow> |
子元素 | 無 |
語法
<Description>
元素使用以下語法:
<Description>flow_description</Description>
範例
以下範例顯示 <Description>
元素,可指定流程的用途:
<!-- api-platform/reference/examples/flow-segments/description-1.xml --> <ProxyEndpoint name="default"> <Flows name="my-conditional-flows"> <Flow name="reports"> <Request> <Description>Based on the path suffix, determine which flow to use</Description> <Step> <Condition>proxy.pathsuffix MatchesPath "/reports"</Condition> <Name>XML-to-JSON-1</Name> </Step> <Step> <Condition>proxy.pathsuffix MatchesPath "/forecasts"</Condition> <Name>XML-to-JSON-1</Name> </Step> </Request> </Flow> </Flows> ... </ProxyEndpoint>
屬性
<Description>
元素沒有屬性。
子元素
<Description>
元素沒有子元素。
<Flow>
定義 Apigee 執行的自訂步驟集合。
類型 | 複雜物件 |
父項元素 |
<Flows> |
子元素 |
<Condition> <Description> <Request> <Response> |
您可以選擇在 <Flow>
上指定 <Condition>
。在這種情況下,Apigee 只會在條件評估為 true 時執行流程中的步驟。否則,Apigee 會略過整個流程。
<Flows>
元素可包含多個 <Flow>
元素,每個元素都有各自的條件和步驟。如有多個 <Flow>
元素,Apigee 只會執行第一個元素,其中沒有條件或條件評估為 true。
您可以定義預設流程,讓系統在其他條件式流程未執行時,一律執行這個流程。視 API Proxy 的設定方式而定,這項工具可能有助於防範惡意攻擊。
語法
<Flow>
元素使用以下語法:
<Flow name="conditional_flow_name"> <Description>flow_description</Description> <Condition>property operator "value"</Condition> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </Flow>
<Flow>
的所有子元素均為選用元素。
範例 1
以下範例顯示簡單的 <Flow>
,該政策一律執行「Log-Message-OK」政策:
<!-- api-platform/reference/examples/flow-segments/flow-1.xml --> <ProxyEndpoint name="default"> <Flows name="my-flow"> <Flow> <Request> <Step> <Name>Log-Message-OK</Name> </Step> </Request> </Flow> </Flows> ... </ProxyEndpoint>
範例 2
以下範例顯示含有多個步驟的 <Flow>
,每個步驟都有各自的條件:
<!-- api-platform/reference/examples/flow-segments/flow-2.xml --> <ProxyEndpoint name="default"> <Flows name="my-conditional-flows"> <Flow name="reports"> <Request> <Description>Based on the path suffix, determine which flow to use</Description> <Step> <Condition>proxy.pathsuffix MatchesPath "/reports"</Condition> <Name>XML-to-JSON-1</Name> </Step> <Step> <Condition>proxy.pathsuffix MatchesPath "/forecasts"</Condition> <Name>Verify-Auth-1</Name> </Step> </Request> </Flow> </Flows> ... </ProxyEndpoint>
範例 3
以下範例顯示條件式流程中的多個流程:
<!-- api-platform/reference/examples/flow-segments/flows-2.xml --> <ProxyEndpoint name="default"> <Flows> <Flow name="my-flow-1"> <Response> <Step> <Condition>response.status.code = 200</Condition> <Name>Assign-Message-1</Name> </Step> </Response> </Flow> <Flow name="my-flow-2"> <Response> <Step> <Condition>response.status.code >= 400</Condition> <Name>Assign-Message-2</Name> </Step> </Response> </Flow> <Flow name="my-flow-3"> <Response> <Step> <Condition>response.status.code >= 300</Condition> <Name>Assign-Message-3</Name> </Step> </Response> </Flow> </Flows> ... </ProxyEndpoint>
Apigee 只會在區隔中執行一個流程,執行第一個沒有條件或條件解析為 true 的流程。
屬性
下表說明 <Flow>
元素的屬性:
屬性 | 類型 | 說明 |
---|---|---|
name |
字串 | (必要) 流程專屬 ID。例如:My-Conditional-Flow-1 。名稱不得包含空格或其他特殊字元。 |
子元素
下表說明 <Flow>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Condition> |
字串 | 定義在執行階段處理的條件陳述式。如果陳述式評估為 true,就會執行流程 (及其所有步驟)。如果陳述式評估為 false,則系統會忽略流程 (及其所有步驟)。 |
<Description> |
字串 | 提供流程的簡短說明。這項說明不會對外公開。 |
<Request> |
複雜物件 | 指定要求區段的步驟和條件。 |
<Response> |
複雜物件 | 指定回應片段的步驟和條件。 |
<Flows>
包含零或多個 <Flow>
元素。
類型 | 複雜物件 |
父項元素 |
<ProxyEndpoint> <TargetEndpoint> |
子元素 |
<Flow> |
如果 <Flows>
中有多個 <Flow>
元素,系統只會執行其中一個 <Flow>
。這會是第一個沒有 <Condition>
或條件解析為 true 的流程。
您可以定義一項預設流程,讓系統在其他流程都未執行時執行這項流程。視 API Proxy 的設定方式而定,這項工具可能有助於防範惡意攻擊。
語法
<Flows>
元素使用以下語法:
<Flows name="flow_name"> <Flow name="conditional_flow_name"> <Description>flow_description</Description> <Condition>property operator "value"</Condition> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </Flow> </Flows>
<Flows>
的所有子元素均為選用元素。
範例 1
以下範例顯示含有單一 <Flow>
的簡單 <Flows>
元素:
<!-- api-platform/reference/examples/flow-segments/flows-1.xml --> <ProxyEndpoint name="default"> <Flows name="my-conditional-flows"> <Flow name="reports"> <Request> <Description>Based on the path suffix, determine which flow to use</Description> <Step> <Condition>proxy.pathsuffix MatchesPath "/reports"</Condition> <Name>XML-to-JSON-1</Name> </Step> <Step> <Condition>proxy.pathsuffix MatchesPath "/forecasts"</Condition> <Name>Verify-Auth-1</Name> </Step> </Request> </Flow> </Flows> ... </ProxyEndpoint>
Apigee 會根據從 proxy
流程變數收集到的路徑後置字元,執行其中一種政策。如果路徑後置字串不符合任何條件,Apigee 就不會執行這個流程。
範例 2
以下範例顯示 <Flows>
中的多個 <Flow>
元素,每個元素都有自己的 <Condition>
:
<!-- api-platform/reference/examples/flow-segments/flows-2.xml --> <ProxyEndpoint name="default"> <Flows> <Flow name="my-flow-1"> <Response> <Step> <Condition>response.status.code = 200</Condition> <Name>Assign-Message-1</Name> </Step> </Response> </Flow> <Flow name="my-flow-2"> <Response> <Step> <Condition>response.status.code >= 400</Condition> <Name>Assign-Message-2</Name> </Step> </Response> </Flow> <Flow name="my-flow-3"> <Response> <Step> <Condition>response.status.code >= 300</Condition> <Name>Assign-Message-3</Name> </Step> </Response> </Flow> </Flows> ... </ProxyEndpoint>
Apigee 只會執行條件評估為 true 的區隔中的第一個流程。之後,Apigee 會略過區段中的其餘流程。
範例 3
以下範例顯示「預設」<Flow>
:
<!-- api-platform/reference/examples/flow-segments/flows-3.xml --> <ProxyEndpoint name="default"> <Flows> <Flow name="my-conditional-flow-1"> <Response> <Step> <Condition>response.status.code = 200</Condition> <Name>Assign-Message-1</Name> </Step> </Response> </Flow> <Flow name="my-conditional-flow-2"> <Response> <Step> <Condition>response.header.someheader = "42"</Condition> <Name>Assign-Message-2</Name> </Step> </Response> </Flow> <Flow name="my-default-flow"> <Response> <Step> <Name>Assign-Message-3</Name> </Step> </Response> </Flow> </Flows> ... </ProxyEndpoint>
Apigee 只會執行條件評估為 true 的區隔中的第一個流程。如果沒有執行任何條件式流程,則會執行本範例中的第三個流程 (沒有條件)。
預設流程可做為防範惡意攻擊的實用工具。
屬性
<Flows>
元素沒有屬性。
子元素
<Flows>
元素包含下列子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Flow> |
複雜物件 | 在條件式流程中定義一組可能的步驟。 |
<Name>
指定要在 <Flow>
中執行的政策 ID。
類型 | 字串 |
父項元素 |
<Step> |
子元素 | 無 |
語法
<Name>
元素使用以下語法:
<Name>policy_name</Name>
範例
以下範例顯示兩個以名稱新增至流程的政策:
<!-- api-platform/reference/examples/flow-segments/name-1.xml --> <ProxyEndpoint name="default"> <Flows name="my-conditional-flows"> <Flow name="reports"> <Request> <Description>Based on the path suffix, determine which flow to use</Description> <Step> <Condition>proxy.pathsuffix MatchesPath "/reports"</Condition> <Name>XML-to-JSON-1</Name> </Step> <Step> <Condition>proxy.pathsuffix MatchesPath "/forecasts"</Condition> <Name>Verify-Auth-1</Name> </Step> </Request> </Flow> </Flows> ... </ProxyEndpoint>
屬性
<Name>
元素沒有屬性。
子元素
<Name>
元素沒有子元素。
<PostFlow>
定義要求和回應的 PostFlow 中要採取的步驟。
類型 | 複雜物件 |
父項元素 |
<ProxyEndpoint> <TargetEndpoint> |
子元素 |
<Description> <Request> <Response> |
<PostFlow>
元素使用以下語法:
語法
<PostFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PostFlow>
範例
以下範例顯示 PostFlow,其中包含已定義要求和回應的步驟:
<!-- api-platform/reference/examples/flow-segments/postflow-1.xml --> <ProxyEndpoint name="default"> <PostFlow name="my-postflows"> <Description>My first PostFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> <Response> <Step> <Name>Set-Response-Headers</Name> </Step> </Response> </PostFlow> ... </ProxyEndpoint>
屬性
下表說明 <PostFlow>
元素的屬性:
屬性 | 類型 | 說明 |
---|---|---|
name |
字串 | 流程的專屬 ID (在端點中不重複)。例如:My-PostFlow-1 。值不得包含空格或其他特殊字元。 |
子元素
下表說明 <PostFlow>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Description> |
字串 | 提供流程的簡短說明。 |
<Request> |
複雜物件 | 定義在要求的 PostFlow 期間執行的政策。 |
<Response> |
複雜物件 | 定義在回應的 PostFlow 期間執行的政策。 |
<EventFlow>
定義 EventFlow
中的步驟。EventFlow
可用於支援串流伺服器傳送的事件。詳情請參閱「串流伺服器傳送的事件」。
類型 | 複雜物件 |
父項元素 |
<TargetEndpoint> |
子元素 |
<Description> <Response> |
EventFlow
元素使用以下語法:
語法
<EventFlow name="flow_name" content-type="text/event-stream">> <Description>flow_description</Description> <Response> <Step> <Name>policy_name</Name> </Step> </Response> </EventFlow>
範例
以下範例顯示 EventFlow:
<TargetEndpoint name="default"> <EventFlow name="EF-1" content-type="text/event-stream"> <Response> <Step> <Name>Raise-Fault-Cred-Invalid</Name> <Condition>fault.name equals "invalid_access_token"</Condition> </Step> </Response> </EventFlow> <HTTPTargetConnection> </TargetEndpoint></pre>
屬性
下表說明 EventFlow 元素的屬性:
屬性 | 類型 | 說明 |
---|---|---|
name |
字串 | 流程的專屬 ID (在端點中不重複)。例如:My-EventFlow-1 。值不得包含空格或其他特殊字元。 |
content-type |
字串 | (必要) 必須設為:content-type="text/event-stream" |
子元素
下表說明 EventFlow 的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Description> |
字串 | 提供流程的簡短說明。 |
<Response> |
複雜物件 | 定義在回應 EventFlow 期間執行的政策。 |
<PostClientFlow>
在 ProxyEndpoint 中定義政策,只有在回應傳回給用戶端後才會執行。這些政策通常會記錄與回應相關的訊息。
類型 | 複雜物件 |
父項元素 |
<ProxyEndpoint> |
子元素 |
<Description> <Response> |
語法
<PostClientFlow>
元素使用以下語法:
<PostClientFlow name="flow_name"> <Description>flow_description</Description> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PostClientFlow>
<PostClientFlow>
的所有子元素均為選用元素。
範例
以下範例說明執行單一政策的簡單 PostClientFlow:
<!-- api-platform/reference/examples/flow-segments/postclientflow-1.xml --> <ProxyEndpoint name="default"> <PostClientFlow name="my-postclientflows"> <Description>My first PostClientFlow. Processed after the response is sent back to the client.</Description> <Response> <Step> <Name>Message-Logging-OK</Name> </Step> </Response> </PostClientFlow> ... </ProxyEndpoint>
屬性
下表說明 <PostClientFlow>
元素的屬性:
屬性 | 類型 | 說明 |
---|---|---|
name |
字串 | 流程專屬 ID。名稱不得包含空格或其他特殊字元。例如 My-PostClientFlow-1 。 |
子元素
下表說明 <PostClientFlow>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Description> |
字串 | 提供流程的簡短說明。 |
<Response> |
複雜物件 | 定義在回應的 PostFlow 期間執行的政策。 |
<PreFlow>
定義要在要求和回應的 PreFlow 中執行的政策。
類型 | 複雜物件 |
父項元素 |
<ProxyEndpoint> <TargetEndpoint> |
子元素 |
<Description> <Request> <Response> |
語法
<PreFlow>
元素使用以下語法:
<PreFlow name="flow_name"> <Description>flow_description</Description> <Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request> <Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response> </PreFlow>
<PreFlow>
的所有子元素均為選用元素。
範例
以下範例顯示 PreFlow,其中定義了要求和回應流程:
<!-- api-platform/reference/examples/flow-segments/preflow-1.xml --> <ProxyEndpoint name="default"> <PreFlow name="my-preFlows"> <Description>My first PreFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> <Response> <Step> <Condition>response.status.code LesserThanOrEquals 300</Condition> <Name>Log-Response-OK</Name> </Step> <Step> <Condition>response.status.code GreaterThan 300</Condition> <Name>Log-Response-NOT-OK</Name> </Step> </Response> </PreFlow> ... </ProxyEndpoint>
屬性
下表說明 <PreFlow>
元素的屬性:
屬性 | 類型 | 說明 |
---|---|---|
name |
字串 | 流程專屬 ID。名稱不得包含空格或其他特殊字元。例如 My-PreFlow-1 。 |
子元素
下表說明 <PreFlow>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Description> |
字串 | 提供流程的簡短說明。 |
<Request> |
複雜物件 | 定義在要求的 PreFlow 期間執行的政策。 |
<Response> |
複雜物件 | 定義在回應的 PreFlow 期間執行的政策。 |
<Request>
定義在流程要求部分執行的政策。
類型 | 複雜物件 |
父項元素 |
<Flow> <PreFlow> <PostFlow> |
子元素 |
<Step> |
語法
<Request>
元素使用以下語法:
<Request> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Request>
<Request>
的所有子元素均為選用元素。
範例
以下範例顯示在 PreFlow 和 PostFlow 中為要求定義的流程:
<!-- api-platform/reference/examples/flow-segments/request-1.xml --> <ProxyEndpoint name="default"> <PreFlow name="my-preFlows"> <Description>My first PreFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> </PreFlow> <PostFlow name="my-postflows"> <Description>My first PostFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> </PostFlow> ... </ProxyEndpoint>
屬性
<Request>
元素沒有屬性。
子元素
下表說明 <Request>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Step> |
字串 | 指定要在要求區段中執行的政策。這類子項可多次顯示。 |
<Response>
定義在流程的回應部分執行的政策。
類型 | 複雜物件 |
父項元素 |
<Flow> <PreFlow> <PostClientFlow> <PostFlow> |
子元素 |
<Step> |
語法
<Response>
元素使用以下語法:
<Response> <Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step> ... </Response>
<Response>
的所有子元素均為選用元素。
範例
以下範例顯示為回應定義的流程,包括 PreFlow 和 PostFlow:
<!-- api-platform/reference/examples/flow-segments/response-1.xml --> <ProxyEndpoint name="default"> <PreFlow name="my-preFlows"> <Description>My first PreFlow</Description> <Response> <Step> <Condition>response.status.code LesserThanOrEquals 300</Condition> <Name>Log-Response-OK</Name> </Step> <Step> <Condition>response.status.code GreaterThan 300</Condition> <Name>Log-Response-NOT-OK</Name> </Step> </Response> </PreFlow> <PostFlow name="my-postflows"> <Description>My first PostFlow</Description> <Response> <Step> <Name>Set-Response-Headers</Name> </Step> </Response> </PostFlow> ... </ProxyEndpoint>
屬性
<Response>
元素沒有屬性。
子元素
下表說明 <Response>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Step> |
字串 | 指定要在回應區段中執行的政策。這類子項可多次顯示。 |
<Step>
指定要執行的政策,以及 (選用) 用來決定是否要執行該政策的條件。
類型 | 複雜物件 |
父項元素 |
<Request> <Response> |
子元素 |
<Condition> <Name> |
<Flow>
中可定義多個步驟,且這些步驟會依照流程 XML 中定義的順序執行。
沒有條件的步驟一律會執行。只有在條件評估為 true 時,系統才會執行含有條件的步驟。如果條件評估結果為 false,Apigee 就會略過該步驟。
語法
<Step>
元素使用以下語法:
<Step> <Condition>property operator "value"</Condition> <Name>policy_name</Name> </Step>
每個 <Step>
只能有一個 <Condition>
和一個 <Name>
,但 <Flow>
中可以有多個步驟。
<Step>
的所有子元素均為選用元素。
範例 1
以下範例顯示一個含有條件的步驟和一個不含條件的步驟:
<!-- api-platform/reference/examples/flow-segments/step-1.xml --> <ProxyEndpoint name="default"> <PostFlow name="my-postflows"> <Description>My first PostFlow</Description> <Request> <Step> <Condition>request.verb = "GET"</Condition> <Name>Log-Request-OK</Name> </Step> </Request> <Response> <Step> <Name>Set-Response-Headers</Name> </Step> </Response> </PostFlow> ... </ProxyEndpoint>
在要求區段中,沒有條件的步驟會在每次執行時執行。只有在回應片段中要求為「GET」時,系統才會執行含有條件的步驟。
範例 2
以下範例顯示單一區段中的多個步驟:
<!-- api-platform/reference/examples/flow-segments/step-2.xml --> <ProxyEndpoint name="default"> <PostFlow name="PostFlow"> <Response> <Step> <Name>Assign-Message-1</Name> </Step> <Step> <Name>Assign-Message-2</Name> </Step> </Response> </PostFlow> ... </ProxyEndpoint>
沒有條件的步驟一律會執行。
屬性
<Step>
元素沒有屬性。
子元素
下表說明 <Step>
的子元素:
子元素 | 類型 | 說明 |
---|---|---|
<Condition> |
字串 | 為在執行階段處理的步驟定義條件式陳述式。如果陳述式評估結果為 true,Apigee 就會執行該步驟。如果陳述式評估為 false,Apigee 就會略過該步驟。 |
<Name> |
字串 | 指定要在目前流程中執行的政策 ID。 |