共用方式為


模擬慢速 API 回應

一目了然
目標: 在測試時為 API 回應加入人工延遲
時間: 5分鐘
插件:延遲插件
前置條件:設定開發代理

開發人員 Proxy 可讓您使用 LatencyPlugin 模擬緩慢的 API 回應。

在開發 Proxy 組態檔中啟用外掛程式,以開始:

檔案: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
  "plugins": [
    {
      "name": "LatencyPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "latencyPlugin"
    }
  ],
  "urlsToWatch": []
}

接下來,指定 API 仿真的最小和最大延遲時間(以毫秒為單位)。

檔案: devproxyrc.json

"latencyPlugin": {
  "minMs": 200,
  "maxMs": 10000
}

完整的設定檔長這樣。

檔案: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
  "plugins": [
    {
      "name": "LatencyPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "latencyPlugin"
    }
  ],
  "urlsToWatch": [
    "https://api.example.com/*"
  ],
  "latencyPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/latencyplugin.schema.json",
    "minMs": 200,
    "maxMs": 10000
  }
}

當回應延遲時,Dev Proxy 會顯示主控台輸出中延遲的總持續時間。

另請參閱