模擬回應

適用於:所有 API 管理 層

如名稱所示,mock-response 原則是用來模擬 API 和作業。 該原則會取消正常的管線執行,並將模擬回應傳回給呼叫者。 原則一律會嘗試傳回最高精確度的回應。 其偏好使用回應內容範例 (若可使用)。 如果提供結構描述而不提供範例,該原則會從結構描述產生範例回應。 如果找不到任何範例或架構,則不會傳回沒有內容的回應。

注意

請依照原則陳述式中提供的順序,來設定原則的元素和子元素。 深入了解如何設定或編輯 APIM 原則

原則陳述式

<mock-response status-code="code" content-type="media type"/>

屬性

屬性 描述 是必要欄位 預設
status-code 指定回應狀態碼,且用來選取對應範例或結構描述。 不允許使用原則運算式。 No 200
Content-Type 指定 Content-Type 回應標頭值,且用來選取對應範例或結構描述。 不允許使用原則運算式。 No

使用方式

使用注意事項

範例

<!-- Returns 200 OK status code. Content is based on an example or schema, if provided for this status code. First found content type is used. If no example or schema is found, the content is empty. -->
<mock-response/>

<!-- Returns 200 OK status code. Content is based on an example or schema, if provided for this status code and media type. If no example or schema found, the content is empty. -->
<mock-response status-code='200' content-type='application/json'/>

如需使用原則的詳細資訊,請參閱: