這個開發 Proxy 能夠從被攔截的 API 請求和回應中生成 HTTP 檔案。 使用 HTTP 檔案特別適用於想要模擬 API 行為或共用可重現 API 互動的開發人員。 HTTP 檔案包含所有相關的要求和回應詳細數據,並以變數取代的敏感性資訊,以取得安全性和重複使用性。
若要使用 Dev Proxy 產生 HTTP 檔案:
在組態檔中, 啟用
HttpFileGeneratorPlugin:{ "plugins": [ { "name": "HttpFileGeneratorPlugin", "enabled": true, "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll", "configSection": "httpFileGeneratorPlugin" } ] // [...] shortened for brevity }選擇性地設定外掛程式:
{ "httpFileGeneratorPlugin": { "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/httpfilegeneratorplugin.schema.json", "includeOptionsRequests": false } // [...] shortened for brevity }-
includeOptionsRequests:判斷是否要在OPTIONS產生的 HTTP 檔案中包含要求。 預設值為false。
-
在組態檔中,在要監看的URL清單中,新增您要為其產生 HTTP 檔案之 API 的 URL:
{ "urlsToWatch": [ "https://api.example.com/*" ] // [...] shortened for brevity }啟動開發代理伺服器:
devproxy按下
r來開始錄製要求。執行您想要包含在 HTTP 檔案中的 API 要求。
按
s停止錄製。開發 Proxy 會產生 HTTP 檔案,並將它儲存在當前目錄中。 此檔案包含所有擷取的要求和回應,其中包含由變數取代的敏感數據,例如持有人令牌和 API 金鑰。 例如:
@jsonplaceholder_typicode_com_api_key = api-key ### # @name getPosts GET https://jsonplaceholder.typicode.com/posts?api-key={{jsonplaceholder_typicode_com_api_key}} Host: jsonplaceholder.typicode.com User-Agent: curl/8.6.0 Accept: */* Via: 1.1 dev-proxy/0.29.0外掛程式會自動為每個主機名和敏感性參數組合建立變數,並在適用時跨要求重複使用它們。
後續步驟
深入瞭解 HttpFileGeneratorPlugin。